Submission #20787

#TimeUsernameProblemLanguageResultExecution timeMemory
20787jjwdi0금 캐기 (IZhO14_divide)C++11
0 / 100
73 ms7272 KiB
#include <bits/stdc++.h> #define INF 987654321 using namespace std; typedef long long ll; struct Mine { int x, g, d; }A[100005]; struct seg_tree { int tree[444444], base; void init(int x) { for(base = 1; base < x; base <<= 1); } void update(int x, int y) { x += base - 1; tree[x] = y; x >>= 1; while(x) { tree[x] = min(tree[x*2], tree[x*2+1]); x >>= 1; } } int RMQ(int s, int e) { s += base - 1, e += base - 1; int res = INF; while(s < e) { if(s & 1) res = min(res, tree[s++]); if(!(e & 1)) res = min(res, tree[e--]); s >>= 1, e >>= 1; } if(s == e) res = min(res, tree[s]); return res; } }S; int N; ll ans, Gsum[100005], Dsum[100005]; ll idx[100005]; int find_idx(ll x) { return lower_bound(idx + 1, idx + N + 1, x) - idx; } int main() { scanf("%d", &N); S.init(N); for(int i=1; i<=N; i++) scanf("%d %d %d", &A[i].x, &A[i].g, &A[i].d); for(int i=1; i<=N; i++) { Gsum[i] += Gsum[i-1] + (ll)A[i].g; Dsum[i] += Dsum[i-1] + (ll)A[i].d; } for(int i=1; i<=N; i++) idx[i] = (ll)A[i].x - Dsum[i-1]; sort(idx + 1, idx + N + 1); ans = A[1].g; for(int i=1; i<=N; i++) { S.update(find_idx(A[i].x - Dsum[i-1]), i - 1); int midx = find_idx(A[i].x - Dsum[i]); midx = S.RMQ(midx, N); if(midx == INF) ans = max(ans, Gsum[i] - Gsum[i - 1]); else ans = max(ans, Gsum[i] - Gsum[midx]); } printf("%lld\n", ans); }

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:42:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
divide.cpp:44:73: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) scanf("%d %d %d", &A[i].x, &A[i].g, &A[i].d);
                                                                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...