Submission #377078

#TimeUsernameProblemLanguageResultExecution timeMemory
377078wzyPotatoes and fertilizers (LMIO19_bulves)C++11
100 / 100
294 ms15224 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, a, b) for(int i = b-1; i>=a ; i--) #define trav(a, x) for(auto& a : x) #define allin(a , x) for(auto a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<ll> vl; typedef vector<pii> vpi; typedef pair<ll,ll> pll; typedef vector<string> vs; typedef vector<pll> vpl; typedef vector<int> vi; std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); const int N = 500005; int a[N] , b[N] , n; int32_t main(){ scanf("%d" , &n); priority_queue<ll> pq; long long ans = 0 , cur = 0; for(int i = 1; i <= n; i ++){ scanf("%d%d" , &a[i] , &b[i]); cur += a[i] - b[i]; if(i < n){ ans += abs(cur); pq.push(max(0ll,cur)) , pq.push(max(0ll,cur)); pq.pop(); } } while(sz(pq)){ ans -= min(pq.top() , cur); pq.pop(); } printf("%lld\n" , ans); }

Compilation message (stderr)

bulves.cpp: In function 'int32_t main()':
bulves.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |  scanf("%d" , &n);
      |  ~~~~~^~~~~~~~~~~
bulves.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |   scanf("%d%d" , &a[i] , &b[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...