Submission #671608

# Submission time Handle Problem Language Result Execution time Memory
671608 2022-12-13T09:46:40 Z Cutebol Divide and conquer (IZhO14_divide) C++17
100 / 100
55 ms 15976 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] += a[i] ;
		prefs[i] = prefs[i-1] + g[i] ;
		mp[pref[i]].push_back(i) ;
	}
	int suf[n];
	suf[n - 1] = pref[n - 1] - x[n - 1];
	for (int i = n - 2; i >= 0; i--) suf[i] = max(suf[i + 1], pref[i] - x[i]); 
	for ( int i = 0 ; i < n ; i ++ ){
		int need = -x[i];
		if (i) need += pref[i - 1];
		int l = i, r = n;
		while (l + 1 < r) {
			int mid = (l + r) >> 1;
			if (suf[mid] >= need) l = mid;
			else r = mid;
		}
		mx = max(mx, prefs[l] - prefs[i] + g[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 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 3 ms 980 KB Output is correct
24 Correct 3 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 3 ms 980 KB Output is correct
24 Correct 3 ms 980 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 5 ms 1876 KB Output is correct
27 Correct 5 ms 1876 KB Output is correct
28 Correct 25 ms 8040 KB Output is correct
29 Correct 28 ms 8160 KB Output is correct
30 Correct 55 ms 15908 KB Output is correct
31 Correct 49 ms 15956 KB Output is correct
32 Correct 51 ms 15916 KB Output is correct
33 Correct 50 ms 15852 KB Output is correct
34 Correct 52 ms 15976 KB Output is correct
35 Correct 52 ms 15904 KB Output is correct
36 Correct 54 ms 15892 KB Output is correct