Submission #1049969

#TimeUsernameProblemLanguageResultExecution timeMemory
1049969vjudge1Art Exhibition (JOI18_art)C++17
100 / 100
134 ms28860 KiB
/*
Author: ArifKraw
Rating: 1379
Goal#1: Beat I_Love_Trott ))))
Goal#2: Not to allow FractalFrog beat myself
*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define ld long double
#define nl '\n'
const ll N = 5e5 + 7;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ld pi = 3.141592653589793;
const ld eps = 1e-12;
const ll zero = 0;
const int MAX = 1e6+5;
const int A = 1e9 + 5;
/*if you cant solve the problem:
try optimized(clever) brute-force;
try prefix sums with/or binary search
try dp
try dfs
try to solve in reversed orderr
try math
try to sort(sort(a+1,a+1+n)
int overflow, array bounds
think about special cases( n=1?)
*/
ll xx1[8]={0, 0,-1, 1, 1,-1, 1,-1};
ll xx2[8]={1,-1, 0, 0, 1, 1,-1,-1};

pair<ll,ll> a[N];
ll pref[N],mxx[N];
void egoist(){
	ll n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].ff>>a[i].ss;
    }
    sort(a+1,a+n+1);
    ll val=0,pos2=0,val2=0,mx=0;
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        pref[i]=pref[i-1]+a[i].ss;
    }
    for(int i=n;i>=1;i--){
        mxx[i]=max(mxx[i+1],pref[i]+a[i].ff);
    }
    for(int i=1;i<=n;i++){
        val=-a[i].ff;
        mx=max(val+mxx[i]-pref[i-1],mx);
    }
    cout<<mx;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("sparse.in", "r", stdin);
    //freopen("sparse.out", "w", stdout);
	egoist();
}

Compilation message (stderr)

art.cpp: In function 'void egoist()':
art.cpp:52:14: warning: unused variable 'pos2' [-Wunused-variable]
   52 |     ll val=0,pos2=0,val2=0,mx=0;
      |              ^~~~
art.cpp:52:21: warning: unused variable 'val2' [-Wunused-variable]
   52 |     ll val=0,pos2=0,val2=0,mx=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...