Submission #672140

#TimeUsernameProblemLanguageResultExecution timeMemory
672140StavabArt Exhibition (JOI18_art)C++14
100 / 100
190 ms24740 KiB
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
     
using namespace std;
     
int main()
{
    int n;
    scanf("%d", &n);
        
    vector<pair<long long, long long>> v(n);
    for(int i = 0; i < n; i++)
    {
        scanf("%lld", &v[i].first);
        scanf("%lld", &v[i].second);
    }
        
    sort(v.begin(), v.end());
        
    vector<long long> sums(n + 1);
    sums[0] = 0;
    for(int i = 0; i < n; i++)
        sums[i + 1] = sums[i] + v[i].second;
        
    long long best = 0;
    long long curMax = -9999999999999999;
    for(int i = n - 1; i >= 0; i--)
    {
        curMax = max(curMax, sums[i + 1] - v[i].first);
        
        best = max(best, curMax - sums[i] + v[i].first);
    }
        
    printf("%lld\n", best);
        
    return 0;
}

Compilation message (stderr)

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