Submission #975336

# Submission time Handle Problem Language Result Execution time Memory
975336 2024-05-04T19:45:59 Z Mr_Husanboy Potatoes and fertilizers (LMIO19_bulves) C++17
24 / 100
71 ms 21444 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]);
        ans -= min(dif[n], q.top());
    }
    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:59:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   59 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
bulves.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 8 ms 2268 KB Output is correct
5 Correct 17 ms 4072 KB Output is correct
6 Correct 45 ms 11492 KB Output is correct
7 Correct 70 ms 21444 KB Output is correct
8 Correct 71 ms 18628 KB Output is correct
9 Correct 59 ms 18052 KB Output is correct
10 Correct 45 ms 16068 KB Output is correct
11 Correct 44 ms 16072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 8 ms 2268 KB Output is correct
5 Correct 17 ms 4072 KB Output is correct
6 Correct 45 ms 11492 KB Output is correct
7 Correct 70 ms 21444 KB Output is correct
8 Correct 71 ms 18628 KB Output is correct
9 Correct 59 ms 18052 KB Output is correct
10 Correct 45 ms 16068 KB Output is correct
11 Correct 44 ms 16072 KB Output is correct
12 Incorrect 20 ms 5080 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Incorrect 1 ms 544 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Incorrect 1 ms 544 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Incorrect 1 ms 544 KB Output isn't correct
5 Halted 0 ms 0 KB -