# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112591 | 2024-11-14T11:12:16 Z | guagua0407 | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 143 ms | 17344 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } signed main() {_ int n; cin>>n; vector<ll> dif(n+1); for(int i=1;i<=n;i++){ int a,b; cin>>a>>b; dif[i]=dif[i-1]+a-b; } priority_queue<ll> pq; pq.push(0); ll ans=0; for(int i=1;i<=n;i++){ if(dif[i]<0){ ans-=dif[i]; dif[i]=0; } pq.push(dif[i]); if(pq.top()>dif[i]){ pq.push(dif[i]); ans+=pq.top()-dif[i]; pq.pop(); } } int cnt=1; while(pq.top()>dif[n]){ int r=pq.top(); pq.pop(); ans+=1ll*cnt*(r-max(dif[n],pq.top())); cnt++; } cout<<ans<<'\n'; return 0; } //maybe its multiset not set
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 516 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 11 ms | 1660 KB | Output is correct |
5 | Correct | 21 ms | 2424 KB | Output is correct |
6 | Correct | 80 ms | 5608 KB | Output is correct |
7 | Correct | 98 ms | 10432 KB | Output is correct |
8 | Correct | 106 ms | 10432 KB | Output is correct |
9 | Correct | 75 ms | 14712 KB | Output is correct |
10 | Correct | 75 ms | 12536 KB | Output is correct |
11 | Correct | 80 ms | 12480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 516 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 11 ms | 1660 KB | Output is correct |
5 | Correct | 21 ms | 2424 KB | Output is correct |
6 | Correct | 80 ms | 5608 KB | Output is correct |
7 | Correct | 98 ms | 10432 KB | Output is correct |
8 | Correct | 106 ms | 10432 KB | Output is correct |
9 | Correct | 75 ms | 14712 KB | Output is correct |
10 | Correct | 75 ms | 12536 KB | Output is correct |
11 | Correct | 80 ms | 12480 KB | Output is correct |
12 | Correct | 53 ms | 4276 KB | Output is correct |
13 | Correct | 95 ms | 12992 KB | Output is correct |
14 | Correct | 77 ms | 17344 KB | Output is correct |
15 | Correct | 111 ms | 15552 KB | Output is correct |
16 | Correct | 143 ms | 14720 KB | Output is correct |
17 | Correct | 74 ms | 12532 KB | Output is correct |
18 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 516 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 504 KB | Output is correct |
8 | Correct | 2 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 504 KB | Output is correct |
10 | Correct | 1 ms | 500 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 516 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 504 KB | Output is correct |
8 | Correct | 2 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 504 KB | Output is correct |
10 | Correct | 1 ms | 500 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 336 KB | Output is correct |
13 | Correct | 2 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 336 KB | Output is correct |
17 | Correct | 1 ms | 504 KB | Output is correct |
18 | Correct | 2 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 516 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 504 KB | Output is correct |
8 | Correct | 2 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 504 KB | Output is correct |
10 | Correct | 1 ms | 500 KB | Output is correct |
11 | Correct | 11 ms | 1660 KB | Output is correct |
12 | Correct | 21 ms | 2424 KB | Output is correct |
13 | Correct | 80 ms | 5608 KB | Output is correct |
14 | Correct | 98 ms | 10432 KB | Output is correct |
15 | Correct | 106 ms | 10432 KB | Output is correct |
16 | Correct | 75 ms | 14712 KB | Output is correct |
17 | Correct | 75 ms | 12536 KB | Output is correct |
18 | Correct | 80 ms | 12480 KB | Output is correct |
19 | Correct | 53 ms | 4276 KB | Output is correct |
20 | Correct | 95 ms | 12992 KB | Output is correct |
21 | Correct | 77 ms | 17344 KB | Output is correct |
22 | Correct | 111 ms | 15552 KB | Output is correct |
23 | Correct | 143 ms | 14720 KB | Output is correct |
24 | Correct | 74 ms | 12532 KB | Output is correct |
25 | Correct | 1 ms | 336 KB | Output is correct |
26 | Correct | 2 ms | 336 KB | Output is correct |
27 | Correct | 1 ms | 336 KB | Output is correct |
28 | Correct | 1 ms | 336 KB | Output is correct |
29 | Correct | 1 ms | 336 KB | Output is correct |
30 | Correct | 1 ms | 504 KB | Output is correct |
31 | Correct | 2 ms | 504 KB | Output is correct |
32 | Correct | 1 ms | 336 KB | Output is correct |
33 | Correct | 42 ms | 4040 KB | Output is correct |
34 | Correct | 67 ms | 12992 KB | Output is correct |
35 | Correct | 105 ms | 17344 KB | Output is correct |
36 | Correct | 96 ms | 14844 KB | Output is correct |
37 | Correct | 82 ms | 15296 KB | Output is correct |
38 | Correct | 92 ms | 17344 KB | Output is correct |
39 | Correct | 52 ms | 13504 KB | Output is correct |
40 | Correct | 60 ms | 12992 KB | Output is correct |
41 | Correct | 53 ms | 12544 KB | Output is correct |
42 | Correct | 62 ms | 12480 KB | Output is correct |
43 | Correct | 55 ms | 12536 KB | Output is correct |
44 | Correct | 56 ms | 12536 KB | Output is correct |
45 | Correct | 117 ms | 17344 KB | Output is correct |
46 | Correct | 73 ms | 12736 KB | Output is correct |
47 | Correct | 66 ms | 12240 KB | Output is correct |