답안 #975338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975338 2024-05-04T19:49:32 Z Mr_Husanboy Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
165 ms 17100 KB
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;



#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
    return a.size();
}

using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;





void solve(){
    int n; cin >> n;
    vector<ll> dif(n + 1);
    for(int i = 1; i <= n; i ++){
        int a, b; cin >> a >> b;
        dif[i] = a - b;
    }
    for(int i = 1; i <= n; i ++) dif[i] += dif[i - 1];

    debug(dif);
    
    priority_queue<ll> q;
    ll ans = 0;
    for(int i = 1; i <= n; i ++){
        ans += abs(dif[i]);
        dif[i] = max(0ll, dif[i]);
        q.push(dif[i]); q.push(dif[i]);
        q.pop();
    }
    while(q.size()){
        ans -= min(dif[n], q.top()); q.pop();
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    auto start = chrono::high_resolution_clock::now();
    #ifndef LOCAL
    if(fileio.size()){
        freopen((fileio + ".in").c_str(), "r", stdin);
        freopen((fileio + ".out").c_str(), "w", stdout);
    }
    #endif
    int testcases = 1;
    #ifdef Tests
    cin >> testcases;
    #endif
    while(testcases --){
        solve();
        if(testcases) cout << '\n';
        #ifdef LOCAL
        else cout << '\n';
        cout << "_________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
    
    cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
    #endif
    return 0;
}   

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:62:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   62 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
bulves.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1504 KB Output is correct
5 Correct 26 ms 2228 KB Output is correct
6 Correct 83 ms 4560 KB Output is correct
7 Correct 113 ms 9416 KB Output is correct
8 Correct 137 ms 10440 KB Output is correct
9 Correct 117 ms 9928 KB Output is correct
10 Correct 89 ms 10128 KB Output is correct
11 Correct 99 ms 8648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1504 KB Output is correct
5 Correct 26 ms 2228 KB Output is correct
6 Correct 83 ms 4560 KB Output is correct
7 Correct 113 ms 9416 KB Output is correct
8 Correct 137 ms 10440 KB Output is correct
9 Correct 117 ms 9928 KB Output is correct
10 Correct 89 ms 10128 KB Output is correct
11 Correct 99 ms 8648 KB Output is correct
12 Correct 39 ms 2524 KB Output is correct
13 Correct 90 ms 11108 KB Output is correct
14 Correct 110 ms 17100 KB Output is correct
15 Correct 139 ms 13512 KB Output is correct
16 Correct 150 ms 12920 KB Output is correct
17 Correct 86 ms 10952 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 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 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 11 ms 1504 KB Output is correct
12 Correct 26 ms 2228 KB Output is correct
13 Correct 83 ms 4560 KB Output is correct
14 Correct 113 ms 9416 KB Output is correct
15 Correct 137 ms 10440 KB Output is correct
16 Correct 117 ms 9928 KB Output is correct
17 Correct 89 ms 10128 KB Output is correct
18 Correct 99 ms 8648 KB Output is correct
19 Correct 39 ms 2524 KB Output is correct
20 Correct 90 ms 11108 KB Output is correct
21 Correct 110 ms 17100 KB Output is correct
22 Correct 139 ms 13512 KB Output is correct
23 Correct 150 ms 12920 KB Output is correct
24 Correct 86 ms 10952 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 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 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 38 ms 4060 KB Output is correct
34 Correct 111 ms 11468 KB Output is correct
35 Correct 163 ms 15860 KB Output is correct
36 Correct 163 ms 13004 KB Output is correct
37 Correct 146 ms 15476 KB Output is correct
38 Correct 159 ms 15732 KB Output is correct
39 Correct 105 ms 11724 KB Output is correct
40 Correct 120 ms 12412 KB Output is correct
41 Correct 109 ms 11652 KB Output is correct
42 Correct 94 ms 11464 KB Output is correct
43 Correct 92 ms 11980 KB Output is correct
44 Correct 92 ms 10884 KB Output is correct
45 Correct 165 ms 15608 KB Output is correct
46 Correct 119 ms 11208 KB Output is correct
47 Correct 105 ms 11468 KB Output is correct