Submission #254001

#TimeUsernameProblemLanguageResultExecution timeMemory
254001MercenaryPotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
196 ms15296 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 5e5 + 5; const int mod = 1e9 + 7; ll c[maxn]; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } ll res = 0; cin >> n; for (int i = 1; i <= n; i++) { ll a, b; cin >> a >> b; c[i] = c[i - 1] + a - b; } for(int i = 1 ; i <= n ; ++i){ if (c[i] > c[n]) { res += c[i] - c[n]; c[i] = c[n]; } else if (c[i] < 0) { res -= c[i]; c[i] = 0; } } priority_queue<ll> pq; for (int i = 1; i <= n; i++) { pq.push(c[i]); pq.push(c[i]); res += pq.top() - c[i]; pq.pop(); } cout << res; }

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...