Submission #950977

# Submission time Handle Problem Language Result Execution time Memory
950977 2024-03-21T03:24:06 Z daoquanglinh2007 Potatoes and fertilizers (LMIO19_bulves) C++17
24 / 100
121 ms 22216 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
const int NM = 5e5;
 
int n, a[NM+5], b[NM+5], c[NM+5], d[NM+5], cur = 0;
priority_queue <int> pq;
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
        c[i] = c[i-1]+a[i];
        d[i] = d[i-1]+b[i];
    }
    pq.push(0);
    for (int i = 1; i < n; i++){
        if (c[i]-d[i] >= pq.top()){
            pq.push(c[i]-d[i]);
            continue;
        }
        cur += pq.top()-(c[i]-d[i]);
        pq.pop();
        if (c[i]-d[i] > 0){
            pq.push(c[i]-d[i]);
            pq.push(c[i]-d[i]);
        }
        else{
            pq.push(0);
            pq.push(0);
        }
    }
    int lst = pq.top(), slope = 0;
    while (lst > c[n]-d[n]){
        cur += slope*(lst-pq.top());
        lst = pq.top();
        pq.pop();
        slope++;
    }
    cout << cur;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 13 ms 9696 KB Output is correct
5 Correct 24 ms 14300 KB Output is correct
6 Correct 78 ms 15300 KB Output is correct
7 Correct 85 ms 21708 KB Output is correct
8 Correct 121 ms 22216 KB Output is correct
9 Correct 88 ms 21700 KB Output is correct
10 Correct 74 ms 21960 KB Output is correct
11 Correct 79 ms 20724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 13 ms 9696 KB Output is correct
5 Correct 24 ms 14300 KB Output is correct
6 Correct 78 ms 15300 KB Output is correct
7 Correct 85 ms 21708 KB Output is correct
8 Correct 121 ms 22216 KB Output is correct
9 Correct 88 ms 21700 KB Output is correct
10 Correct 74 ms 21960 KB Output is correct
11 Correct 79 ms 20724 KB Output is correct
12 Incorrect 35 ms 14300 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Incorrect 1 ms 4444 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Incorrect 1 ms 4444 KB Output isn't correct
6 Halted 0 ms 0 KB -