답안 #1093074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093074 2024-09-25T19:41:38 Z Seb Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
147 ms 11200 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> //order_of_key = menores, find_by_order = consultar indexado en 0, regresa iterador
using ordered_set =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vii = vector<int>;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define mid ((l+r)>>1)
#define f first
#define s second
#define pb push_back
#define MP make_pair
#define all(x) (x).begin(),(x).end()
#define inicio(x) (*(x).begin())
#define rinicio(x) (*(x).rbegin())
#define SZ(x) (int)(x.size())

const ll MAXN = (ll)3e3 + 5;
const ll MAXK = (ll)3e4 + 5;
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e12 + 5;
const ll OFFSET = (ll)1e6;

priority_queue<ll> pq;
ll sum, brute, M, ans, pre;

void tc() {
    ll N; cin >> N;
    for (int i = 0; i < N; i++) {
        ll a, b; cin >> a >> b;
        a -= b;
        sum += a;
        brute += abs(sum);

        pq.push(sum);
        pq.push(sum);
        if (i < N - 1) pq.pop();
    }

    M = 2;
    pq.push(sum);
    pq.push(0);

    while (!pq.empty() && pq.top() > sum) {
        pq.pop();
        M--;
    }

    pre = pq.top();
    while (!pq.empty() && pq.top() >= 0) {
        ans -= M*abs(pre - pq.top());
        M--;
        pre = pq.top();
        pq.pop();
    }
    cout << brute - ans << "\n";
    return;
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++) {
        tc();
    }
    return 0;
}

//checa tus constantes, n = 1? overflow?
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 11 ms 1332 KB Output is correct
5 Correct 22 ms 2008 KB Output is correct
6 Correct 74 ms 5836 KB Output is correct
7 Correct 110 ms 11196 KB Output is correct
8 Correct 129 ms 9152 KB Output is correct
9 Correct 108 ms 8648 KB Output is correct
10 Correct 83 ms 6240 KB Output is correct
11 Correct 93 ms 6340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 11 ms 1332 KB Output is correct
5 Correct 22 ms 2008 KB Output is correct
6 Correct 74 ms 5836 KB Output is correct
7 Correct 110 ms 11196 KB Output is correct
8 Correct 129 ms 9152 KB Output is correct
9 Correct 108 ms 8648 KB Output is correct
10 Correct 83 ms 6240 KB Output is correct
11 Correct 93 ms 6340 KB Output is correct
12 Correct 35 ms 3024 KB Output is correct
13 Correct 85 ms 9412 KB Output is correct
14 Correct 110 ms 11196 KB Output is correct
15 Correct 135 ms 9148 KB Output is correct
16 Correct 136 ms 8568 KB Output is correct
17 Correct 79 ms 6388 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 564 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 540 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 11 ms 1332 KB Output is correct
12 Correct 22 ms 2008 KB Output is correct
13 Correct 74 ms 5836 KB Output is correct
14 Correct 110 ms 11196 KB Output is correct
15 Correct 129 ms 9152 KB Output is correct
16 Correct 108 ms 8648 KB Output is correct
17 Correct 83 ms 6240 KB Output is correct
18 Correct 93 ms 6340 KB Output is correct
19 Correct 35 ms 3024 KB Output is correct
20 Correct 85 ms 9412 KB Output is correct
21 Correct 110 ms 11196 KB Output is correct
22 Correct 135 ms 9148 KB Output is correct
23 Correct 136 ms 8568 KB Output is correct
24 Correct 79 ms 6388 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 564 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 540 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 35 ms 3028 KB Output is correct
34 Correct 88 ms 8364 KB Output is correct
35 Correct 145 ms 10996 KB Output is correct
36 Correct 147 ms 8636 KB Output is correct
37 Correct 121 ms 9176 KB Output is correct
38 Correct 147 ms 11196 KB Output is correct
39 Correct 92 ms 7276 KB Output is correct
40 Correct 111 ms 6708 KB Output is correct
41 Correct 86 ms 6340 KB Output is correct
42 Correct 85 ms 6328 KB Output is correct
43 Correct 80 ms 7112 KB Output is correct
44 Correct 88 ms 7632 KB Output is correct
45 Correct 138 ms 11200 KB Output is correct
46 Correct 106 ms 6612 KB Output is correct
47 Correct 101 ms 6624 KB Output is correct