답안 #731780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731780 2023-04-28T01:10:12 Z thienhx Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
195 ms 14992 KB
#include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
 
using ll = long long;   
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using ld = long double;
using db = double;
//--------------------
#define           F   first
#define           S   second
#define          pb   push_back
#define       sz(x)   (int)((x).size())
#define      all(x)   (x).begin(), (x).end()
#define     rall(x)   (x).rbegin(), (x).rend()
#define    mem(f,x)   memset(f , x , sizeof(f))
#define __lcm(x, y)   (1LL * ((x) / __gcd((x), (y))) * (y))

template<class T> bool maximize(T &a,const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a,const T &b){ return (a > b ? a = b, 1 : 0); }
//--------------------
#define PROBLEM "test"

const int MOD = 1e9 + 7; // 998244353;
const ll INF = 1e18;
const db PI = acos(-1);
const int dx[4]{0, 1, 0, -1}, dy[4]{1, 0, -1, 0}; // U R D L
const int ddx[4]{-1, 1, 1, -1}, ddy[4]{1, 1, -1, -1}; // UR DR DL UL
const int kx[8]{1, 1, 2, 2, -1, -1, -2, -2}, ky[8]{-2, 2, -1, 1, -2, 2, -1, 1};

//-----------------[PROBLEM SOLUTION]-----------------//

void solve() {
    ll n, res = 0, pref = 0;
    cin >> n;

    ll x, y;
    priority_queue<ll> pq;
    for (int i = 0; i < n; i++) pq.push(0);
    for (int i = 0; i < n - 1; i++) {
        cin >> x >> y;

        pref += x - y;

        pq.push(pref);

        if (pref < pq.top()) {
            res += pq.top() - pref; 
            pq.pop(); pq.push(pref);
        }
    }

    cin >> x >> y;
    pref += x - y;
    while(pq.size() && pref < pq.top())
        res += pq.top() - pref, pq.pop();

    cout << res << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if (fopen(PROBLEM".inp", "r")){
        freopen(PROBLEM".inp", "r", stdin);
        freopen(PROBLEM".out", "w", stdout);
    }

    constexpr bool MULTI_TEST = 0;
    int t = 1;
    if(MULTI_TEST) cin >> t;
    while(t--)
        solve();
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(PROBLEM".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(PROBLEM".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 15 ms 1620 KB Output is correct
5 Correct 30 ms 2896 KB Output is correct
6 Correct 99 ms 7644 KB Output is correct
7 Correct 139 ms 14992 KB Output is correct
8 Correct 155 ms 13148 KB Output is correct
9 Correct 125 ms 12396 KB Output is correct
10 Correct 97 ms 10204 KB Output is correct
11 Correct 106 ms 10136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 15 ms 1620 KB Output is correct
5 Correct 30 ms 2896 KB Output is correct
6 Correct 99 ms 7644 KB Output is correct
7 Correct 139 ms 14992 KB Output is correct
8 Correct 155 ms 13148 KB Output is correct
9 Correct 125 ms 12396 KB Output is correct
10 Correct 97 ms 10204 KB Output is correct
11 Correct 106 ms 10136 KB Output is correct
12 Correct 48 ms 3980 KB Output is correct
13 Correct 121 ms 11836 KB Output is correct
14 Correct 128 ms 14980 KB Output is correct
15 Correct 153 ms 13248 KB Output is correct
16 Correct 195 ms 12452 KB Output is correct
17 Correct 89 ms 10228 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 15 ms 1620 KB Output is correct
12 Correct 30 ms 2896 KB Output is correct
13 Correct 99 ms 7644 KB Output is correct
14 Correct 139 ms 14992 KB Output is correct
15 Correct 155 ms 13148 KB Output is correct
16 Correct 125 ms 12396 KB Output is correct
17 Correct 97 ms 10204 KB Output is correct
18 Correct 106 ms 10136 KB Output is correct
19 Correct 48 ms 3980 KB Output is correct
20 Correct 121 ms 11836 KB Output is correct
21 Correct 128 ms 14980 KB Output is correct
22 Correct 153 ms 13248 KB Output is correct
23 Correct 195 ms 12452 KB Output is correct
24 Correct 89 ms 10228 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 47 ms 3980 KB Output is correct
34 Correct 109 ms 11908 KB Output is correct
35 Correct 162 ms 14980 KB Output is correct
36 Correct 141 ms 12512 KB Output is correct
37 Correct 121 ms 13136 KB Output is correct
38 Correct 153 ms 14992 KB Output is correct
39 Correct 97 ms 11124 KB Output is correct
40 Correct 120 ms 10300 KB Output is correct
41 Correct 101 ms 10172 KB Output is correct
42 Correct 86 ms 10188 KB Output is correct
43 Correct 83 ms 10212 KB Output is correct
44 Correct 91 ms 10112 KB Output is correct
45 Correct 180 ms 14924 KB Output is correct
46 Correct 73 ms 10460 KB Output is correct
47 Correct 91 ms 9688 KB Output is correct