Submission #557249

#TimeUsernameProblemLanguageResultExecution timeMemory
557249Ai7081Art Exhibition (JOI18_art)C++17
100 / 100
210 ms14204 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define st first
#define nd second

const int N = 5e5+5;

ll n, sum[N], max_dp, ans;
pair<ll, ll> p[N];

int main() {
    scanf(" %lld", &n);
    for (int i=1; i<=n; i++) {
        scanf(" %lld %lld", &p[i].st, &p[i].nd);
    }
    sort(p+1, p+1+n);
    for (int i=1; i<=n; i++) sum[i]  = sum[i-1] + p[i].nd;
    max_dp = p[1].st - sum[0];
    for (int i=1; i<=n; i++) {
        ans = max(ans, sum[i] - p[i].st + max_dp);
        if (i<n) max_dp = max(max_dp, p[i+1].st - sum[i]);
    }
    printf("%lld", ans);
    return 0;
}

Compilation message (stderr)

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