Submission #940239

#TimeUsernameProblemLanguageResultExecution timeMemory
94023912345678Potatoes and fertilizers (LMIO19_bulves)C++17
24 / 100
67 ms18908 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=5e5+5; ll n, a[nx], b[nx], d[nx], res; priority_queue<ll> pq; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>a[i]>>b[i], d[i]=d[i-1]+(a[i]-b[i]); for (int i=1; i<n; i++) { if (d[i]<0) res-=d[i], d[i]=0; else if (d[i]>d[n]) res+=d[i]-d[n]; //pq.push(d[i]); //pq.push(d[i]); //pq.pop(); } cout<<res<<'\n'; //while (!pq.empty()) cout<<pq.top()<<' ', pq.pop(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...