답안 #1083437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083437 2024-09-03T06:30:12 Z hqminhuwu Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
143 ms 19396 KB
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;

#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

template<class X, class Y>
    bool minz(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } return false;
    }
template<class X, class Y>
    bool maxz(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } return false;
    }

const int N = 5e5 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;

ll n, x, ans, y;
ll d[N];
priority_queue <ll> q;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef hqm
        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    #endif

    cin >> n;

    forr (i, 1, n)
        q.push(0);

    forr (i, 1, n){
        cin >> x >> y;
        d[i] = d[i - 1] + x - y;
    }

    forr (i, 1, n){
        q.push(d[i]);
        q.push(d[i]);
        ans += abs(q.top() - d[i]);
        q.pop();
    }

    while (!q.empty()){
        if (q.top() <= d[n]) break;
        ans += q.top() - d[n];
        q.pop();
    }

    cout << ans  << endl;

    return 0;
}
/*



*/

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 11 ms 2164 KB Output is correct
5 Correct 23 ms 4056 KB Output is correct
6 Correct 70 ms 9924 KB Output is correct
7 Correct 123 ms 19396 KB Output is correct
8 Correct 123 ms 17384 KB Output is correct
9 Correct 95 ms 16736 KB Output is correct
10 Correct 79 ms 14500 KB Output is correct
11 Correct 90 ms 14524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 11 ms 2164 KB Output is correct
5 Correct 23 ms 4056 KB Output is correct
6 Correct 70 ms 9924 KB Output is correct
7 Correct 123 ms 19396 KB Output is correct
8 Correct 123 ms 17384 KB Output is correct
9 Correct 95 ms 16736 KB Output is correct
10 Correct 79 ms 14500 KB Output is correct
11 Correct 90 ms 14524 KB Output is correct
12 Correct 39 ms 5588 KB Output is correct
13 Correct 83 ms 15036 KB Output is correct
14 Correct 100 ms 19392 KB Output is correct
15 Correct 129 ms 17600 KB Output is correct
16 Correct 143 ms 16828 KB Output is correct
17 Correct 72 ms 14524 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 11 ms 2164 KB Output is correct
12 Correct 23 ms 4056 KB Output is correct
13 Correct 70 ms 9924 KB Output is correct
14 Correct 123 ms 19396 KB Output is correct
15 Correct 123 ms 17384 KB Output is correct
16 Correct 95 ms 16736 KB Output is correct
17 Correct 79 ms 14500 KB Output is correct
18 Correct 90 ms 14524 KB Output is correct
19 Correct 39 ms 5588 KB Output is correct
20 Correct 83 ms 15036 KB Output is correct
21 Correct 100 ms 19392 KB Output is correct
22 Correct 129 ms 17600 KB Output is correct
23 Correct 143 ms 16828 KB Output is correct
24 Correct 72 ms 14524 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 26 ms 5304 KB Output is correct
34 Correct 72 ms 15016 KB Output is correct
35 Correct 109 ms 19332 KB Output is correct
36 Correct 104 ms 16832 KB Output is correct
37 Correct 114 ms 17596 KB Output is correct
38 Correct 107 ms 19252 KB Output is correct
39 Correct 81 ms 15464 KB Output is correct
40 Correct 86 ms 15080 KB Output is correct
41 Correct 79 ms 14456 KB Output is correct
42 Correct 77 ms 14524 KB Output is correct
43 Correct 71 ms 14524 KB Output is correct
44 Correct 71 ms 14576 KB Output is correct
45 Correct 129 ms 19372 KB Output is correct
46 Correct 87 ms 14788 KB Output is correct
47 Correct 68 ms 14448 KB Output is correct