답안 #242677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242677 2020-06-28T23:41:30 Z WhaleVomit Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
277 ms 25064 KB
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

int main() { FAST
    int n; cin >> n;
    vector<ll> diff(n);
    M00(i, n) {
        ll a, b; cin >> a >> b;
        diff[i] = a-b;
    }
    vector<ll> d(n);
    d[0] = diff[0];
    MOO(i, 1, n) d[i] = d[i-1] + diff[i];
    ll ans = 0;
    M00(i, n) ans += abs(d[i]);
    priority_queue<ll> pq;
    M00(i, n) {
        pq.push(d[i]); pq.push(d[i]);
        pq.pop();
    }
    vector<ll> changes;
    while(!pq.empty()) {
        changes.pb(pq.top());
        pq.pop();
    }
    reverse(all(changes));
    ll curslope = sz(changes);
    ll last = 0;
    M00(i, sz(changes)) {
        if(changes[i] < 0) {
            curslope--;
            continue;
        }
        if(changes[i] > d[n-1]) break;
        ans -= curslope * (changes[i] - last);
        last = changes[i];
        curslope--;
    }
    finish(ans);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 29 ms 2676 KB Output is correct
5 Correct 44 ms 4848 KB Output is correct
6 Correct 133 ms 12652 KB Output is correct
7 Correct 266 ms 25064 KB Output is correct
8 Correct 212 ms 23268 KB Output is correct
9 Correct 238 ms 22500 KB Output is correct
10 Correct 133 ms 20196 KB Output is correct
11 Correct 147 ms 20196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 29 ms 2676 KB Output is correct
5 Correct 44 ms 4848 KB Output is correct
6 Correct 133 ms 12652 KB Output is correct
7 Correct 266 ms 25064 KB Output is correct
8 Correct 212 ms 23268 KB Output is correct
9 Correct 238 ms 22500 KB Output is correct
10 Correct 133 ms 20196 KB Output is correct
11 Correct 147 ms 20196 KB Output is correct
12 Correct 66 ms 6512 KB Output is correct
13 Correct 165 ms 17636 KB Output is correct
14 Correct 272 ms 25060 KB Output is correct
15 Correct 223 ms 23140 KB Output is correct
16 Correct 243 ms 22500 KB Output is correct
17 Correct 139 ms 20148 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 424 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 424 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 424 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 29 ms 2676 KB Output is correct
12 Correct 44 ms 4848 KB Output is correct
13 Correct 133 ms 12652 KB Output is correct
14 Correct 266 ms 25064 KB Output is correct
15 Correct 212 ms 23268 KB Output is correct
16 Correct 238 ms 22500 KB Output is correct
17 Correct 133 ms 20196 KB Output is correct
18 Correct 147 ms 20196 KB Output is correct
19 Correct 66 ms 6512 KB Output is correct
20 Correct 165 ms 17636 KB Output is correct
21 Correct 272 ms 25060 KB Output is correct
22 Correct 223 ms 23140 KB Output is correct
23 Correct 243 ms 22500 KB Output is correct
24 Correct 139 ms 20148 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 63 ms 6512 KB Output is correct
33 Correct 158 ms 17636 KB Output is correct
34 Correct 270 ms 24932 KB Output is correct
35 Correct 245 ms 22628 KB Output is correct
36 Correct 216 ms 23136 KB Output is correct
37 Correct 255 ms 25060 KB Output is correct
38 Correct 161 ms 21220 KB Output is correct
39 Correct 178 ms 20124 KB Output is correct
40 Correct 139 ms 20196 KB Output is correct
41 Correct 148 ms 20196 KB Output is correct
42 Correct 143 ms 20200 KB Output is correct
43 Correct 140 ms 20192 KB Output is correct
44 Correct 277 ms 25060 KB Output is correct
45 Correct 171 ms 20580 KB Output is correct
46 Correct 158 ms 18408 KB Output is correct
47 Correct 5 ms 512 KB Output is correct