Submission #1363678

#TimeUsernameProblemLanguageResultExecution timeMemory
1363678vjudge1Potatoes and fertilizers (LMIO19_bulves)C++20
100 / 100
81 ms8556 KiB
/*
address:https://vjudge.net/problem/OJUZ-LMIO19_bulves

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e5 + 5;
int n;
LL a[N];
LL ans;
priority_queue<LL>q;
int main() {
    scanf("%d", &n);
    for (int i = 1;i <= n;++i) {
        int x, y;scanf("%d%d", &x, &y);
        a[i] = a[i - 1] + x - y;
    }
    for (int i = 0;i <= n;++i) {
        LL x = min(a[n], max(0ll, a[i]));
        ans += abs(x - a[i]);
        q.push(x);
        if (x < q.top()) {
            ans += q.top() - x;
            q.push(x);
            q.pop();
        }
    }
    printf("%lld", ans);
    return 0;
}

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bulves.cpp:16:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         int x, y;scanf("%d%d", &x, &y);
      |                  ~~~~~^~~~~~~~~~~~~~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...