Submission #671561

# Submission time Handle Problem Language Result Execution time Memory
671561 2022-12-13T08:19:04 Z Cutebol Divide and conquer (IZhO14_divide) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
 
using namespace std;
 
//void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
   
const int N = 1e6 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e7 ;

int n , mx ;
vector <int> x , g , a ;
vector <int> pref , prefs ;
map <int , vector <int> > mp ;

void solve(){
	
	cin >> n ;
	x.resize(n) , g.resize(n) , a.resize(n) , pref.resize(n) , prefs.resize(n) ;
	for ( int i = 0 ; i < n ; i ++ )
		cin >> x[i] >> g[i] >> a[i] ;
	pref[0] = a[0] ;
	prefs[0] = g[0] ;
	for ( int i = 1 ; i < n ; i ++ ){
		pref[i] = pref[i-1] ;
		pref[i] += x[i-1] - x[i] + a[i] ;
		prefs[i] = prefs[i-1] + g[i] ;
		mp[pref[i]].push_back(i) ;
	}
	set<int> cur ;
	for ( int i = 0 ; i < n ; i ++ ){
		int ans = prefs[i] ;
		if ( pref[i] < 0 ){
			if ( cur.lower_bound(pref[i]) == cur.begin() )
				ans = g[i] ;
			else{
				ans -= prefs[*mp[*cur.lower_bound(-pref[i])].begin()] ;
			}
		}
//		cout << pref[i] << ' ' ;
		mx = max( mx , ans ) ;
		cur.insert(pref[i]) ;
	}
	cout << mx << endl ;
}
 
signed main(){
//  fopn("talent") ;
    Scaramouche ;
    int t = 1 ;
//      cin >> t ;
    while ( t -- ) solve() ; 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -