Submission #1033872

#TimeUsernameProblemLanguageResultExecution timeMemory
1033872don_ban_tinhArt Exhibition (JOI18_art)C++14
100 / 100
260 ms12116 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define S second
#define F first

int main()
{
    int n;
    scanf("%d", &n);
    vector<pair<ll, ll>> q(n);
    for(int i = 0; i < n; ++i)
    {
        scanf("%lld %lld", &q[i].F, &q[i].S);
    }

    sort(q.begin(), q.end());

    vector<ll> p(n + 1, 0);
    for(int i = 1; i <= n; ++i)
    {
        p[i] = p[i - 1] + q[i - 1].S;
    }

    ll mx = 0, ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        mx = max(mx, -p[i - 1] + q[i - 1].F);
        ans = max(ans, p[i] - q[i - 1].F + mx);
    }

    printf("%lld", ans);

    return 0;
}

Compilation message (stderr)

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