Submission #1008527

#TimeUsernameProblemLanguageResultExecution timeMemory
1008527khanhtbArt Exhibition (JOI18_art)C++17
100 / 100
125 ms24816 KiB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 5e5+8;
ll n,p[N];
pll a[N];
void solve(){
    cin >> n;
    for(ll i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se;
    sort(a+1,a+n+1);
    for(ll i = 1; i <= n; i++) p[i] = p[i-1]+a[i].se;
    ll mx = 0;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        mx = max(mx,a[i].fi-p[i-1]);
        ans = max(ans,mx+p[i]-a[i].fi);
    }
    cout << ans;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if(fopen("test.inp","r")){
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    ll T = 1;
    // cin >> T;
    while(T--){
        solve();
        // cout << '\n';
    }
}

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
art.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...