# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377078 | wzy | Potatoes and fertilizers (LMIO19_bulves) | C++11 | 294 ms | 15224 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |