답안 #414583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414583 2021-05-30T17:02:58 Z Aldas25 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
247 ms 26940 KB
#pragma GCC target ("avx2")
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 4e18;
const ld PI = asin(1) * 2;

int n;
ll a[MAXN], b[MAXN], dif[MAXN], pref[MAXN];

ll dp[2][31000];

int main()
{
    FAST_IO;

    cin >> n;
    FOR(i, 1, n) cin >> a[i] >> b[i];

    FOR(i, 1, n) {
        dif[i] = a[i]-b[i];
        pref[i] = pref[i-1] + dif[i];
    }

    priority_queue<ll> q;

    ll ans = 0;

    FOR(i, 1, n) {
        REP(2) q.push(max(0ll, pref[i]));
        q.pop();
        ans += abs(pref[i]);
    }

    while (!q.empty()) {
        ans -= min(pref[n], q.top());
        q.pop();
    }

    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 18 ms 2944 KB Output is correct
5 Correct 37 ms 5256 KB Output is correct
6 Correct 120 ms 11216 KB Output is correct
7 Correct 179 ms 21088 KB Output is correct
8 Correct 212 ms 21136 KB Output is correct
9 Correct 178 ms 20996 KB Output is correct
10 Correct 157 ms 21104 KB Output is correct
11 Correct 164 ms 21160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 18 ms 2944 KB Output is correct
5 Correct 37 ms 5256 KB Output is correct
6 Correct 120 ms 11216 KB Output is correct
7 Correct 179 ms 21088 KB Output is correct
8 Correct 212 ms 21136 KB Output is correct
9 Correct 178 ms 20996 KB Output is correct
10 Correct 157 ms 21104 KB Output is correct
11 Correct 164 ms 21160 KB Output is correct
12 Correct 59 ms 6312 KB Output is correct
13 Correct 160 ms 14828 KB Output is correct
14 Correct 181 ms 21084 KB Output is correct
15 Correct 218 ms 21064 KB Output is correct
16 Correct 218 ms 21032 KB Output is correct
17 Correct 148 ms 21052 KB Output is correct
18 Correct 2 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 540 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 18 ms 2944 KB Output is correct
12 Correct 37 ms 5256 KB Output is correct
13 Correct 120 ms 11216 KB Output is correct
14 Correct 179 ms 21088 KB Output is correct
15 Correct 212 ms 21136 KB Output is correct
16 Correct 178 ms 20996 KB Output is correct
17 Correct 157 ms 21104 KB Output is correct
18 Correct 164 ms 21160 KB Output is correct
19 Correct 59 ms 6312 KB Output is correct
20 Correct 160 ms 14828 KB Output is correct
21 Correct 181 ms 21084 KB Output is correct
22 Correct 218 ms 21064 KB Output is correct
23 Correct 218 ms 21032 KB Output is correct
24 Correct 148 ms 21052 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 540 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 536 KB Output is correct
32 Correct 2 ms 452 KB Output is correct
33 Correct 57 ms 7024 KB Output is correct
34 Correct 140 ms 18008 KB Output is correct
35 Correct 247 ms 26940 KB Output is correct
36 Correct 241 ms 24500 KB Output is correct
37 Correct 204 ms 25020 KB Output is correct
38 Correct 239 ms 26940 KB Output is correct
39 Correct 166 ms 23124 KB Output is correct
40 Correct 182 ms 21528 KB Output is correct
41 Correct 154 ms 22060 KB Output is correct
42 Correct 151 ms 22100 KB Output is correct
43 Correct 144 ms 22180 KB Output is correct
44 Correct 145 ms 22132 KB Output is correct
45 Correct 240 ms 26904 KB Output is correct
46 Correct 180 ms 22388 KB Output is correct
47 Correct 160 ms 19336 KB Output is correct