Submission #800318

# Submission time Handle Problem Language Result Execution time Memory
800318 2023-08-01T13:20:52 Z leeminhduc2 Potatoes and fertilizers (LMIO19_bulves) C++17
30 / 100
1000 ms 1376 KB
///leeminhduc2
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define ii pair<int,int>
#define sz(x) (int) (x).size()
#define pb push_back
using namespace std;
template<class T1,class T2> bool maximize(T1 &a,T2 b) {return(a<b ? a=b,1:0);};
template<class T1,class T2> bool minimize(T1 &a,T2 b) {return(a>b ? a=b,1:0);};

int n;
ll a,b,lst,d[500010];
void leeminhduc2()
{
    cin >> n;
    a=0,b=0;
    priority_queue<int> pq;
    for (int i=1;i<=n;i++) pq.push(0);
    for( int i=1;i<=n;i++)
    {
        ll u,v;
        cin >> u >> v;
        d[i]=u-v;
        d[i]+=d[i-1];
        //cout <<d[i] << " ";
    }
    for (int i=1;i<=n;i++)
    {
        ll  x;
        x=d[i];
        ++a;
        pq.push(x);
        pq.push(x);
        b-=x;
        if (i<n){
        while (sz(pq)&&a>=0)
        {
            ll cur=pq.top(),cnt=0;
            while (sz(pq)&&cur==pq.top())
            {
                ++cnt;
                pq.pop();
            }
            a-=cnt;
            b+=cur*cnt;
            lst=cur;
        }
        for (int j=1;j<=-a;j++) pq.push(lst);
        b+=lst*a;
        a=0;
        }
        else
        {
            while (sz(pq)&&pq.top()>=d[n]) 
    {
        ll cur=pq.top(),cnt=0;
            while (sz(pq)&&cur==pq.top())
            {
                ++cnt;
                pq.pop();
            }
            a-=cnt;
            b+=cur*cnt;
            lst=cur;
    }
        }
        
    }
    
    cout << a*d[n]+b;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    leeminhduc2();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 202 ms 396 KB Output is correct
3 Correct 220 ms 472 KB Output is correct
4 Execution timed out 1076 ms 1376 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 202 ms 396 KB Output is correct
3 Correct 220 ms 472 KB Output is correct
4 Execution timed out 1076 ms 1376 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 202 ms 396 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 189 ms 408 KB Output is correct
10 Correct 30 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 202 ms 396 KB Output is correct
3 Correct 220 ms 472 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 8 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 189 ms 408 KB Output is correct
11 Correct 30 ms 404 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 93 ms 408 KB Output is correct
18 Correct 128 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 202 ms 396 KB Output is correct
3 Correct 220 ms 472 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 8 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 189 ms 408 KB Output is correct
11 Execution timed out 1076 ms 1376 KB Time limit exceeded
12 Halted 0 ms 0 KB -