Submission #973138

#TimeUsernameProblemLanguageResultExecution timeMemory
973138hihihahPotatoes and fertilizers (LMIO19_bulves)C++14
24 / 100
148 ms17864 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(), x.end() #define pii pair<int, int> int n; int a[500009]; int b[500009]; int64_t pre[500009]; void hihihah() { cin >> n; for(int i = 1; i <= n; i ++) cin >> a[i] >> b[i]; for(int i = 1; i <= n; i ++) { pre[i] = pre[i - 1] + a[i] - b[i]; } priority_queue<int64_t> p; int64_t ans = 0; p.push(0); for(int i = 1; i <= n; i ++) { if(pre[i] < 0) { ans += -pre[i]; pre[i] = 0; } if(p.top() > pre[i]) ans += p.top() - pre[i]; p.push(pre[i]); p.push(pre[i]); p.pop(); } while(p.top() > pre[n]) { ans += p.top(); p.pop(); } cout << ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define orz "mo" if(fopen(orz".inp", "r")) { freopen(orz".inp", "r", stdin); // freopen(orz".out", "w", stdout); } int t = 1; // cin >> t; while(t --) { hihihah(); } return 0; }

Compilation message (stderr)

bulves.cpp: In function 'int32_t main()':
bulves.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(orz".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...