답안 #483353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483353 2021-10-28T22:01:14 Z MilosMilutinovic 금 캐기 (IZhO14_divide) C++14
48 / 100
67 ms 11584 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

/*
pref[j] - pref[i - 1] >= x[j] - x[i]
pref[j] - x[j] >= pref[i - 1] - x[i]
*/
const int N=101000;
int n,x[N],g[N],d[N];
ll pf[N],tot[N],dp[N];
struct node{
	ll mn;
	node(){ mn=1e16; }
}nd[4*N];
void upd(int p) {
	nd[p].mn=min(nd[p*2].mn,nd[p*2+1].mn);
}
void modify(int p,int l,int r,int tl,ll x) {
	if (l==r) nd[p].mn=min(nd[p].mn,x);
	else {
		int md=(l+r)>>1;
		if (tl<=md) modify(p*2,l,md,tl,x);
		else modify(p*2+1,md+1,r,tl,x);
		upd(p);
	}
}
ll get(int p,int l,int r,int tl,int tr) {
	if (l>tr||r<tl) return 1e18;
	if (tl<=l&&r<=tr) return nd[p].mn;
	int md=(l+r)>>1;
	return min(get(p*2,l,md,tl,tr),get(p*2+1,md+1,r,tl,tr));
}
int main() {
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d%d%d",x+i,g+i,d+i);
	rep(i,1,n+1) pf[i]=pf[i-1]+d[i];
	rep(i,1,n+1) tot[i]=tot[i-1]+g[i];
//	rep(i,1,n+1) printf("%lld ",tot[i]); puts("");
	vector<ll> c;
	rep(i,1,n+1) c.pb(pf[i]-x[i]),c.pb(pf[i-1]-x[i]);
	sort(all(c)); c.erase(unique(all(c)),c.end());
	auto val=[&](ll i) {
		return lower_bound(all(c),i)-c.begin();
	};
	rep(i,1,n+1) {
		modify(1,0,SZ(c)-1,val(pf[i-1]-x[i]),tot[i-1]);
		dp[i]=tot[i]-get(1,0,SZ(c)-1,0,val(pf[i]-x[i]));
	}
	ll ans=0;
	rep(i,1,n+1) ans=max(ans,dp[i]);
	printf("%lld",ans);
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
divide.cpp:53:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  rep(i,1,n+1) scanf("%d%d%d",x+i,g+i,d+i);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 3 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3468 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3464 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 3 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3468 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3464 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3468 KB Output is correct
14 Correct 2 ms 3468 KB Output is correct
15 Correct 2 ms 3472 KB Output is correct
16 Correct 2 ms 3532 KB Output is correct
17 Correct 2 ms 3532 KB Output is correct
18 Correct 2 ms 3532 KB Output is correct
19 Correct 2 ms 3532 KB Output is correct
20 Correct 2 ms 3532 KB Output is correct
21 Correct 3 ms 3532 KB Output is correct
22 Correct 3 ms 3660 KB Output is correct
23 Correct 5 ms 4044 KB Output is correct
24 Correct 5 ms 3916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 3 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3468 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3464 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3468 KB Output is correct
14 Correct 2 ms 3468 KB Output is correct
15 Correct 2 ms 3472 KB Output is correct
16 Correct 2 ms 3532 KB Output is correct
17 Correct 2 ms 3532 KB Output is correct
18 Correct 2 ms 3532 KB Output is correct
19 Correct 2 ms 3532 KB Output is correct
20 Correct 2 ms 3532 KB Output is correct
21 Correct 3 ms 3532 KB Output is correct
22 Correct 3 ms 3660 KB Output is correct
23 Correct 5 ms 4044 KB Output is correct
24 Correct 5 ms 3916 KB Output is correct
25 Correct 5 ms 3896 KB Output is correct
26 Correct 7 ms 4252 KB Output is correct
27 Correct 8 ms 4300 KB Output is correct
28 Correct 34 ms 7152 KB Output is correct
29 Correct 36 ms 7352 KB Output is correct
30 Correct 67 ms 11584 KB Output is correct
31 Correct 64 ms 10408 KB Output is correct
32 Correct 67 ms 10480 KB Output is correct
33 Correct 62 ms 10288 KB Output is correct
34 Incorrect 64 ms 10268 KB Output isn't correct
35 Halted 0 ms 0 KB -