Submission #723471

#TimeUsernameProblemLanguageResultExecution timeMemory
723471BobonbushArt Exhibition (JOI18_art)C++17
100 / 100
204 ms24736 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MODULO = 1e9+7; const ll INF = 1e18+1; template<class X ,class Y> bool Minimize(X &x , Y y) { if(x > y) { x = y ; return true; } return false; } template<class X ,class Y> bool Maximize(X &x , Y y ) { if(x < y) { x = y; return true; } return false; } template<class X ,class Y> void Add(X &x , Y y) { x += y; if( x >= MODULO) x -= MODULO; } template<class X ,class Y> void Sub(X &x , Y y ) { x -= y ; if( x < 0 ) x += MODULO; } const int N = 5e5+1; int n ; pair<ll , ll >a[N]; long long dp[N]; void Input() { cin >> n ; for(int i = 1 ; i <= n ; i++) { cin >> a[i].first >> a[i].second; } } void Process() { sort(a+1 , a+1 + n); if(n <= 5000) { ll ans = -INF; for(int i = 1; i <= n ; i++) { ll sum = 0; for(int j = i; j <= n ;j++) { sum += a[j].second; Maximize(ans , sum - (a[j].first - a[i].first)); } } cout << ans; return ; } for(int i = 1 ; i <= n ; i++) { dp[i] = a[i].second + a[i].first; } for(int i = 2 ; i <= n ;i++) { Maximize(dp[i] , dp[i-1] + a[i].second); } long long ans = -INF; for(int i = 1 ; i <= n ; i++) { Maximize(ans , dp[i] - a[i].first); } cout << ans; } int main() { ios_base :: sync_with_stdio(0);cin.tie(0); int test = 1; while(test--) { Input(); Process(); cout <<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...