답안 #836447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836447 2023-08-24T11:18:12 Z urieg Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
1000 ms 15232 KB
#include<bits/stdc++.h>
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define ve vector
typedef long long ll;
using namespace std;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    ll a,b ;
    priority_queue<ll>q;
    long long ans = 0;
    cin>>n;
    vector<ll>d(n);
    for(int i = 0;i<n;i++){
        cin>>a>>b;
        d[i] = a-b;
        if(i)d[i] += d[i-1];
    }

    if(d[0] < 0){
        ans += -d[0];
        d[0]=0;
    }
    q.push(d[0]);
    for(int i = 1; i<n-1; i++){
        if(d[i]<0){
            ans += -d[i];
            d[i]=0;
        }
        q.push(d[i]);
        if(q.top()>d[i]){
            ans += q.top()-d[i];
            q.push(d[i]);
            q.pop();
        }
    }
    if(n>1){
        while(q.top()>d[n-1]){
            ans += q.top()-d[n-1];
            q.pop();
        }
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 10 ms 1644 KB Output is correct
5 Correct 22 ms 2900 KB Output is correct
6 Correct 78 ms 7772 KB Output is correct
7 Correct 83 ms 15232 KB Output is correct
8 Execution timed out 1078 ms 13304 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 10 ms 1644 KB Output is correct
5 Correct 22 ms 2900 KB Output is correct
6 Correct 78 ms 7772 KB Output is correct
7 Correct 83 ms 15232 KB Output is correct
8 Execution timed out 1078 ms 13304 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Execution timed out 1088 ms 340 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Execution timed out 1088 ms 340 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Execution timed out 1088 ms 340 KB Time limit exceeded
11 Halted 0 ms 0 KB -