Submission #1033995

#TimeUsernameProblemLanguageResultExecution timeMemory
1033995vjudge1Art Exhibition (JOI18_art)C++17
100 / 100
147 ms24664 KiB
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ii long long int 
#define pb push_back
#define fi first
#define se second
#define Op operator
#define bp __builtin_popcount
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define TT ll tt;cin>>tt;while(tt--){Test_Case();}
#define T Test_Case() ;
using namespace std;
const ii N = 5e5 , M = 1e6 , mod = 1e9 + 7 , Ones = 1 , Zero = 0;
const ll oo = 1e18 ;
pair<ll,ll> a[N + 5] ; 
ii dp[N + 5] ; 
bool comp(pair<ii,ii> aa , pair<ii,ii> bb) {
    return (aa.fi < bb.fi || (aa.fi == bb.fi && aa.se > bb.se)) ; 
}
void Test_Case(){
    ii n , ans = 0 ; cin >> n ; 
    for(ii i = 1 ; i <= n ; i ++) {
        cin >> a[i].fi >> a[i].se ; 
    }
    sort(a + 1 , a + n + 1 , comp) ;
    dp[1]= a[1].se ; ans = dp[1] ; 
    for(ii i = 2 ; i <= n ; i ++) {
        dp[i] = a[i].se ;
        dp[i] = max(dp[i] , dp[i - 1] + a[i].se - (a[i].fi - a[i - 1].fi)) ; ans = max(ans , dp[i]) ;  
    }
    cout << ans << endl ; 
}
int main(){
    Faster
    T ;
}
                    //////    //    //  //    //  //////
                    //        //   //   //    //      //
                    //////    //////      ////      //
                        //    //  //      //      //
                    //////    //   //    //       ////////
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...