Submission #625342

#TimeUsernameProblemLanguageResultExecution timeMemory
625342StavabArt Exhibition (JOI18_art)C++14
0 / 100
0 ms212 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());
    
    long long s = 0;
    long long curMin = v[0].first;
    long long best = 0;
    int ind;
    for(int i = 0; i < n; i++)
    {
        s += v[i].second;
        
        
        long long cur = s + curMin - v[i].first;
        if(best < cur)
        {
            best = s + curMin - v[i].first;
            ind = i;
        }
    }
    
    long long answer = best;
    s = v[0].second;
    for(int i = 1; i < ind; i++)
    {
        answer = max(answer, best - s + v[i].first - curMin);
        
        s += v[i].second;
    }
    
    printf("%lld", answer);
    
    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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
art.cpp:25:9: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |     int ind;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...