답안 #284212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284212 2020-08-27T03:17:43 Z fivefourthreeone Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
175 ms 15336 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 500001;
ll arr[mxN];
ll c[mxN];
int n;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    priority_queue<ll> pq;
    cin>>n;
    ll k, a, b;
    ll ans = 0;
    owo(i, 1, n+1) {
        cin>>a>>b;
        c[i] = c[i-1] + a - b;
    }
    owo(i, 1, n+1) {
        if(c[i]>c[n]) {
            ans+=c[i]-c[n];
            c[i] = c[n];
        }
        if(c[i]<0) {
            ans-=c[i];
            c[i] = 0;
        }
        pq.push(c[i]);
        k = c[i];
        while(pq.top()>k) {
            ans+=pq.top()-k;
            ll temp = pq.top();
            pq.pop();
            pq.push(k);
            k = temp;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Compilation message

bulves.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
bulves.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 9 ms 1792 KB Output is correct
5 Correct 17 ms 2940 KB Output is correct
6 Correct 52 ms 7924 KB Output is correct
7 Correct 106 ms 15212 KB Output is correct
8 Correct 94 ms 13420 KB Output is correct
9 Correct 87 ms 12672 KB Output is correct
10 Correct 70 ms 10476 KB Output is correct
11 Correct 69 ms 10476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 9 ms 1792 KB Output is correct
5 Correct 17 ms 2940 KB Output is correct
6 Correct 52 ms 7924 KB Output is correct
7 Correct 106 ms 15212 KB Output is correct
8 Correct 94 ms 13420 KB Output is correct
9 Correct 87 ms 12672 KB Output is correct
10 Correct 70 ms 10476 KB Output is correct
11 Correct 69 ms 10476 KB Output is correct
12 Correct 28 ms 4212 KB Output is correct
13 Correct 78 ms 11060 KB Output is correct
14 Correct 109 ms 15212 KB Output is correct
15 Correct 90 ms 13420 KB Output is correct
16 Correct 95 ms 12780 KB Output is correct
17 Correct 90 ms 10496 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 9 ms 1792 KB Output is correct
12 Correct 17 ms 2940 KB Output is correct
13 Correct 52 ms 7924 KB Output is correct
14 Correct 106 ms 15212 KB Output is correct
15 Correct 94 ms 13420 KB Output is correct
16 Correct 87 ms 12672 KB Output is correct
17 Correct 70 ms 10476 KB Output is correct
18 Correct 69 ms 10476 KB Output is correct
19 Correct 28 ms 4212 KB Output is correct
20 Correct 78 ms 11060 KB Output is correct
21 Correct 109 ms 15212 KB Output is correct
22 Correct 90 ms 13420 KB Output is correct
23 Correct 95 ms 12780 KB Output is correct
24 Correct 90 ms 10496 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 41 ms 4212 KB Output is correct
33 Correct 100 ms 10996 KB Output is correct
34 Correct 175 ms 15212 KB Output is correct
35 Correct 157 ms 12904 KB Output is correct
36 Correct 95 ms 13420 KB Output is correct
37 Correct 155 ms 15336 KB Output is correct
38 Correct 97 ms 11500 KB Output is correct
39 Correct 102 ms 10992 KB Output is correct
40 Correct 93 ms 10476 KB Output is correct
41 Correct 96 ms 10476 KB Output is correct
42 Correct 96 ms 10476 KB Output is correct
43 Correct 100 ms 10480 KB Output is correct
44 Correct 117 ms 15236 KB Output is correct
45 Correct 88 ms 10732 KB Output is correct
46 Correct 104 ms 10348 KB Output is correct
47 Correct 2 ms 384 KB Output is correct