답안 #384553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384553 2021-04-01T20:44:33 Z ritul_kr_singh 금 캐기 (IZhO14_divide) C++17
100 / 100
46 ms 7660 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

struct SegmentTree{
	vector<int> a; int sz = 1, ID = 1e18;
	SegmentTree(vector<int> &v){
		while(sz < (int)v.size()) sz += sz;
		a.assign(2*sz, ID);
		build(v, 0, 0, sz);
	}
	void build(vector<int> &v, int x, int lx, int rx){
		if(rx-lx==1){
			if(lx<(int)v.size()) a[x] = v[lx];
			return;
		}
		int mx = (lx+rx)/2;
		build(v, 2*x+1, lx, mx);
		build(v, 2*x+2, mx, rx);
		a[x] = min(a[2*x+1], a[2*x+2]);
	}
	int get(int val, int x, int lx, int rx){
		if(rx-lx==1) return (a[x] <= val ? lx : sz);
		int mx = (lx+rx)/2;
		if(a[2*x+1]<=val) return get(val, 2*x+1, lx, mx);
		if(a[2*x+2]<=val) return get(val, 2*x+2, mx, rx);
		return sz;
	}
	int get(int val){ return get(val, 0, 0, sz); }
};

signed main(){
	cin.tie(0)->sync_with_stdio(0);

	int n, ans = 0; cin >> n;
	vector<int> a(n+1), b(n+1), c(n+1);
	for(int i=1; i<=n; ++i){
		cin >> c[i] >> b[i] >> a[i];
		ans = max(ans, b[i]);
		a[i] += a[i-1];
		b[i] += b[i-1];
	}
	for(int i=0; i<n; ++i) a[i] -= c[i+1];

	SegmentTree st(a);
	for(int i=1; i<=n; ++i){
		int sub = (i < n ?  c[i+1] : 0LL);
		int j = st.get(a[i] + sub - c[i]);
		if(j<i) ans = max(ans, b[i] - b[j]);
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 4 ms 1004 KB Output is correct
27 Correct 5 ms 1004 KB Output is correct
28 Correct 22 ms 3692 KB Output is correct
29 Correct 22 ms 3820 KB Output is correct
30 Correct 46 ms 7660 KB Output is correct
31 Correct 37 ms 6508 KB Output is correct
32 Correct 38 ms 6508 KB Output is correct
33 Correct 38 ms 6380 KB Output is correct
34 Correct 37 ms 6380 KB Output is correct
35 Correct 40 ms 6892 KB Output is correct
36 Correct 42 ms 7020 KB Output is correct