답안 #254001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254001 2020-07-29T08:52:32 Z Mercenary Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
196 ms 15296 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;

ll c[maxn];
int n;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    ll res = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        ll a, b;
        cin >> a >> b;
        c[i] = c[i - 1] + a - b;
    }
    for(int i = 1 ; i <= n ; ++i){
        if (c[i] > c[n]) {
            res += c[i] - c[n];
            c[i] = c[n];
        } else if (c[i] < 0) {
            res -= c[i];
            c[i] = 0;
        }
    }
    priority_queue<ll> pq;
    for (int i = 1; i <= n; i++) {
        pq.push(c[i]); pq.push(c[i]);
        res += pq.top() - c[i];
        pq.pop();
    }
    cout << res;
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 10 ms 1664 KB Output is correct
5 Correct 20 ms 2932 KB Output is correct
6 Correct 69 ms 7792 KB Output is correct
7 Correct 141 ms 15224 KB Output is correct
8 Correct 128 ms 13428 KB Output is correct
9 Correct 117 ms 12652 KB Output is correct
10 Correct 92 ms 10476 KB Output is correct
11 Correct 95 ms 10480 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 10 ms 1664 KB Output is correct
5 Correct 20 ms 2932 KB Output is correct
6 Correct 69 ms 7792 KB Output is correct
7 Correct 141 ms 15224 KB Output is correct
8 Correct 128 ms 13428 KB Output is correct
9 Correct 117 ms 12652 KB Output is correct
10 Correct 92 ms 10476 KB Output is correct
11 Correct 95 ms 10480 KB Output is correct
12 Correct 39 ms 4212 KB Output is correct
13 Correct 91 ms 11044 KB Output is correct
14 Correct 147 ms 15212 KB Output is correct
15 Correct 121 ms 13420 KB Output is correct
16 Correct 116 ms 12724 KB Output is correct
17 Correct 97 ms 10476 KB Output is correct
18 Correct 1 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 0 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 1 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 0 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 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 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 0 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 10 ms 1664 KB Output is correct
12 Correct 20 ms 2932 KB Output is correct
13 Correct 69 ms 7792 KB Output is correct
14 Correct 141 ms 15224 KB Output is correct
15 Correct 128 ms 13428 KB Output is correct
16 Correct 117 ms 12652 KB Output is correct
17 Correct 92 ms 10476 KB Output is correct
18 Correct 95 ms 10480 KB Output is correct
19 Correct 39 ms 4212 KB Output is correct
20 Correct 91 ms 11044 KB Output is correct
21 Correct 147 ms 15212 KB Output is correct
22 Correct 121 ms 13420 KB Output is correct
23 Correct 116 ms 12724 KB Output is correct
24 Correct 97 ms 10476 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 444 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 44 ms 4212 KB Output is correct
33 Correct 105 ms 10948 KB Output is correct
34 Correct 196 ms 15212 KB Output is correct
35 Correct 164 ms 12780 KB Output is correct
36 Correct 135 ms 13420 KB Output is correct
37 Correct 181 ms 15296 KB Output is correct
38 Correct 111 ms 11372 KB Output is correct
39 Correct 117 ms 10984 KB Output is correct
40 Correct 97 ms 10476 KB Output is correct
41 Correct 97 ms 10476 KB Output is correct
42 Correct 103 ms 10476 KB Output is correct
43 Correct 110 ms 10604 KB Output is correct
44 Correct 155 ms 15212 KB Output is correct
45 Correct 118 ms 10820 KB Output is correct
46 Correct 106 ms 10352 KB Output is correct
47 Correct 1 ms 384 KB Output is correct