답안 #1040337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040337 2024-08-01T01:36:19 Z vjudge1 금 캐기 (IZhO14_divide) C++17
100 / 100
18 ms 7384 KB
#include<bits/stdc++.h>
#define INF 1e18
#define fi first
#define se second
#define FOR(i, k, n) for(ll i = k; i <= n; i++)
#define FOR1(i, k, n) for(ll i = k; i >= n; i--)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define re return 0
#define mii map<int, int>
#define input "BAI1.inp"
#define output "BAI1.out"
#define rf 	freopen(input, "r", stdin); freopen(output, "w", stdout)
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
ll f[maxn], f1[maxn];
ll T[maxn * 4];
struct shape{
	int x, g, d;
};
shape a[maxn];
int main()
{
	fastio;
	int n;
	cin >> n;
	FOR(i, 1, n)
	{
		cin >> a[i].x >> a[i].g >> a[i].d;
	}
	vii v;
	ll ans = a[1].g;
	v.pb({- a[1].x, 1});
	f[1] = a[1].d;
	f1[1] = a[1].g;
	FOR(i, 2, n)
	{
		ans = max(ans, (ll)a[i].g);
		f1[i] = f1[i - 1] + a[i].g;
		f[i] = f[i - 1] + a[i].d;
		ll res = f[i] - a[i].x;
		ll t = f[i - 1] - a[i].x;
		if(t < v.back().fi)
			v.pb({t, i});
		int l = 0, r = v.size() - 1, vt = -1;
		while(l <= r)
		{
			int mid = (l + r) >> 1;
			if(v[mid].fi <= res)
			{
				vt = mid;
				r = mid - 1;
			}
			else
				l = mid + 1;
		}
		if(vt != -1)
		{
			vt = v[vt].se;
			ans = max(ans, f1[i] - f1[vt - 1]);
		}
		res = f[i - 1] - a[i].x;
	}
	cout << ans;
	re;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 620 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 9 ms 4444 KB Output is correct
29 Correct 8 ms 4700 KB Output is correct
30 Correct 17 ms 7036 KB Output is correct
31 Correct 13 ms 5980 KB Output is correct
32 Correct 13 ms 6004 KB Output is correct
33 Correct 13 ms 5736 KB Output is correct
34 Correct 15 ms 6360 KB Output is correct
35 Correct 17 ms 7188 KB Output is correct
36 Correct 18 ms 7384 KB Output is correct