# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112588 | 2024-11-14T11:10:52 Z | guagua0407 | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 75 ms | 12368 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #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); } int main() {_ int n; cin>>n; vector<int> 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<int> 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 | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 KB | Output is correct |
4 | Correct | 10 ms | 1360 KB | Output is correct |
5 | Correct | 22 ms | 2004 KB | Output is correct |
6 | Correct | 73 ms | 5832 KB | Output is correct |
7 | Correct | 75 ms | 12368 KB | Output is correct |
8 | Incorrect | 75 ms | 10328 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 KB | Output is correct |
4 | Correct | 10 ms | 1360 KB | Output is correct |
5 | Correct | 22 ms | 2004 KB | Output is correct |
6 | Correct | 73 ms | 5832 KB | Output is correct |
7 | Correct | 75 ms | 12368 KB | Output is correct |
8 | Incorrect | 75 ms | 10328 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 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 | 504 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 2 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 504 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 2 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 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 | 504 KB | Output is correct |
7 | Correct | 1 ms | 336 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 | 336 KB | Output is correct |
11 | Correct | 2 ms | 336 KB | Output is correct |
12 | Correct | 2 ms | 336 KB | Output is correct |
13 | Correct | 1 ms | 504 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 2 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 336 KB | Output is correct |
17 | Correct | 2 ms | 336 KB | Output is correct |
18 | Correct | 1 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 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 | 504 KB | Output is correct |
7 | Correct | 1 ms | 336 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 | 336 KB | Output is correct |
11 | Correct | 10 ms | 1360 KB | Output is correct |
12 | Correct | 22 ms | 2004 KB | Output is correct |
13 | Correct | 73 ms | 5832 KB | Output is correct |
14 | Correct | 75 ms | 12368 KB | Output is correct |
15 | Incorrect | 75 ms | 10328 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |