Submission #200104

#TimeUsernameProblemLanguageResultExecution timeMemory
200104SamAndPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
257 ms15332 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;

int n;
long long a[N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld", &a[i]);
        int x;
        scanf("%d", &x);
        a[i] -= x;
        a[i] += a[i - 1];
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] < 0)
        {
            ans += (-a[i]);
            a[i] = 0;
        }
        if (a[i] > a[n])
        {
            ans += (a[i] - a[n]);
            a[i] = a[n];
        }
    }
    priority_queue<long long> q;
    q.push(a[1]);
    for (int i = 2; i <= n; ++i)
    {
        q.push(a[i]);
        if (a[i] < q.top())
        {
            ans += (q.top() - a[i]);
            q.pop();
            q.push(a[i]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message (stderr)

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