-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweight.cpp
85 lines (67 loc) · 1.71 KB
/
weight.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vpi = vector<pair<ll, ll>>;
void solve() {
int e, w;
cin >> e >> w;
vector<vi> x(e, vi(w));
vector<vi> cnt(e, vi(101));
ll randm = 0;
for (int i = 0; i < e; i++) {
for (int j = 0; j < w; j++) {
ll v;
cin >> v;
cnt[i][j]+=v;
if (i == e - 1) randm += v;
}
}
vector<vpi> st;
ll ans = 0;
for (int i = 0; i < e; i++) {
cout << ans << endl;
bool works = true;
bool done = false;
ll thing = -1;
for (int k = 0; k < st.size(); k++) {
bool curbad = works;
if (!curbad && !done) {
thing = k;
done = true;
}
for (int g = 0; g < st[k].size(); g++) {
ll v = st[k][g].first;
ll cn = st[k][g].second;
ll excess = max(0LL, cn - cnt[i][v]);
if (!works) excess = cnt[i][v];
cnt[i][v] -= excess;
ans += excess;
if (excess > 0) works = false;
}
}
if (thing != -1) {
for (int j = st.size() - 1; j >= 0; j--) {
st.pop_back();
if (j == thing) break;
}
}
vpi lol(101);
for (int v = 0; v <= 100; v++) {
lol[v] = {v, cnt[i][v]};
ans+=cnt[i][v];
}
st.push_back(lol);
}
cout << ans << endl;
cout << ans + randm << endl;
}
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
cout << "Case #" << i << ": ";
solve();
}
return 0;
}