Submission #671586

# Submission time Handle Problem Language Result Execution time Memory
671586 2022-12-13T08:55:50 Z viwlesxq Divide and conquer (IZhO14_divide) C++17
100 / 100
32 ms 7884 KB
#include <bits/stdc++.h>
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef string str;

#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	ll x[n], g[n], d[n];
	for (int i = 0; i < n; i++) cin >> x[i] >> g[i] >> d[i];
	ll ans = *max_element(g, g + n);
	vector <ll> pref_d(n), pref_g(n), suff_max(n);
	pref_d[0] = d[0];
	pref_g[0] = g[0];
	for (int i = 1; i < n; i++) {
		pref_d[i] = pref_d[i - 1] + d[i];
		pref_g[i] = pref_g[i - 1] + g[i];
	}
	suff_max[n - 1] = pref_d[n - 1] - x[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		suff_max[i] = max(suff_max[i + 1], pref_d[i] - x[i]);
	}
	for (int i = 0; i < n; i++) {
		int l = i, r = n;
		while (l + 1 < r) {
			int mid = (l + r) / 2;
			ll add = 0;
			if (i) add = pref_d[i - 1] - x[i];
			else add = x[i];
			if (suff_max[mid] >= add) l = mid;
			else r = mid;
		} 
		ans = max(ans, pref_g[l] - pref_g[i] + g[i]);
	}
	cout << ans;
}
# 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 212 KB Output is correct
14 Correct 0 ms 212 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 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 212 KB Output is correct
14 Correct 0 ms 212 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 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 14 ms 2644 KB Output is correct
29 Correct 16 ms 3900 KB Output is correct
30 Correct 32 ms 7884 KB Output is correct
31 Correct 26 ms 6740 KB Output is correct
32 Correct 27 ms 6732 KB Output is correct
33 Correct 27 ms 6612 KB Output is correct
34 Correct 26 ms 6604 KB Output is correct
35 Correct 26 ms 4948 KB Output is correct
36 Correct 27 ms 4960 KB Output is correct