Submission #483354

# Submission time Handle Problem Language Result Execution time Memory
483354 2021-10-28T22:01:44 Z MilosMilutinovic Divide and conquer (IZhO14_divide) C++14
100 / 100
84 ms 14128 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[8*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);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6604 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Correct 3 ms 6604 KB Output is correct
4 Correct 3 ms 6604 KB Output is correct
5 Correct 3 ms 6604 KB Output is correct
6 Correct 3 ms 6604 KB Output is correct
7 Correct 3 ms 6604 KB Output is correct
8 Correct 3 ms 6604 KB Output is correct
9 Correct 4 ms 6604 KB Output is correct
10 Correct 3 ms 6604 KB Output is correct
11 Correct 3 ms 6604 KB Output is correct
12 Correct 3 ms 6604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6604 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Correct 3 ms 6604 KB Output is correct
4 Correct 3 ms 6604 KB Output is correct
5 Correct 3 ms 6604 KB Output is correct
6 Correct 3 ms 6604 KB Output is correct
7 Correct 3 ms 6604 KB Output is correct
8 Correct 3 ms 6604 KB Output is correct
9 Correct 4 ms 6604 KB Output is correct
10 Correct 3 ms 6604 KB Output is correct
11 Correct 3 ms 6604 KB Output is correct
12 Correct 3 ms 6604 KB Output is correct
13 Correct 3 ms 6604 KB Output is correct
14 Correct 3 ms 6604 KB Output is correct
15 Correct 3 ms 6604 KB Output is correct
16 Correct 4 ms 6604 KB Output is correct
17 Correct 4 ms 6604 KB Output is correct
18 Correct 4 ms 6732 KB Output is correct
19 Correct 3 ms 6604 KB Output is correct
20 Correct 4 ms 6604 KB Output is correct
21 Correct 5 ms 6732 KB Output is correct
22 Correct 4 ms 6732 KB Output is correct
23 Correct 10 ms 6988 KB Output is correct
24 Correct 7 ms 6988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6604 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Correct 3 ms 6604 KB Output is correct
4 Correct 3 ms 6604 KB Output is correct
5 Correct 3 ms 6604 KB Output is correct
6 Correct 3 ms 6604 KB Output is correct
7 Correct 3 ms 6604 KB Output is correct
8 Correct 3 ms 6604 KB Output is correct
9 Correct 4 ms 6604 KB Output is correct
10 Correct 3 ms 6604 KB Output is correct
11 Correct 3 ms 6604 KB Output is correct
12 Correct 3 ms 6604 KB Output is correct
13 Correct 3 ms 6604 KB Output is correct
14 Correct 3 ms 6604 KB Output is correct
15 Correct 3 ms 6604 KB Output is correct
16 Correct 4 ms 6604 KB Output is correct
17 Correct 4 ms 6604 KB Output is correct
18 Correct 4 ms 6732 KB Output is correct
19 Correct 3 ms 6604 KB Output is correct
20 Correct 4 ms 6604 KB Output is correct
21 Correct 5 ms 6732 KB Output is correct
22 Correct 4 ms 6732 KB Output is correct
23 Correct 10 ms 6988 KB Output is correct
24 Correct 7 ms 6988 KB Output is correct
25 Correct 6 ms 7040 KB Output is correct
26 Correct 8 ms 7268 KB Output is correct
27 Correct 9 ms 7244 KB Output is correct
28 Correct 36 ms 9224 KB Output is correct
29 Correct 35 ms 9272 KB Output is correct
30 Correct 71 ms 11824 KB Output is correct
31 Correct 66 ms 11768 KB Output is correct
32 Correct 64 ms 11792 KB Output is correct
33 Correct 63 ms 11776 KB Output is correct
34 Correct 68 ms 11824 KB Output is correct
35 Correct 84 ms 14104 KB Output is correct
36 Correct 70 ms 14128 KB Output is correct