Submission #1329922

#TimeUsernameProblemLanguageResultExecution timeMemory
1329922fahim903Art Exhibition (JOI18_art)C++20
100 / 100
573 ms31720 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    vector<vector<ll>> a(n, vector<ll>(2, 0));
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1];
    }
    sort(a.begin(),a.end());
    vector<ll> ps(n);
    ps[0] = a[0][1];
    for(int i = 1;i<n;i++){
        ps[i] = ps[i-1] +a[i][1];
    }
    ll mn = -INFINITY;
    ll ans = -INFINITY;
    for(int i = 0;i<n;i++){
        ll x = a[i][0]+a[i][1]-ps[i];
        mn = max(mn,x);
        ll f = ps[i]-a[i][0] + mn;
        ans = max(f,ans); 
    }
    cout<<ans<<endl;
}

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:17:13: warning: overflow in conversion from 'float' to 'll' {aka 'long long int'} changes value from '-Inff' to '-9223372036854775808' [-Woverflow]
   17 |     ll mn = -INFINITY;
      |             ^
art.cpp:18:14: warning: overflow in conversion from 'float' to 'll' {aka 'long long int'} changes value from '-Inff' to '-9223372036854775808' [-Woverflow]
   18 |     ll ans = -INFINITY;
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...