Submission #340690

# Submission time Handle Problem Language Result Execution time Memory
340690 2020-12-28T08:00:59 Z Kerim Divide and conquer (IZhO14_divide) C++17
100 / 100
116 ms 16492 KB
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000000000007
#define ll long long
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
using namespace std;
ll F[MAXN],e[MAXN],g[MAXN],ans,res;
int x[MAXN],n,c;
map<ll,int>pm;
void upd(int x,ll val){for(;x<MAXN;x+=x&(-x))F[x]=min(F[x],val);	}
ll tap(int x){for(res=INF;x;x-=x&(-x))res=min(res,F[x]);return res;}	
int main(){
    for(int i=0;i<MAXN;i++)F[i]=INF;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%d%lld%lld",x+i,g+i,e+i);
    	g[i]+=g[i-1];e[i]+=e[i-1];
    	pm[e[i-1]-x[i]]=pm[e[i]-x[i]]=1;
    }tr(it,pm)it->second=++c;
    for(int i=1;i<=n;i++){
    	upd(pm[e[i-1]-x[i]],g[i-1]);
		ans=max(ans,g[i]-tap(pm[e[i]-x[i]]));	
    }printf("%lld\n",ans);
	return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
divide.cpp:16:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |      scanf("%d%lld%lld",x+i,g+i,e+i);
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 1 ms 1900 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 1 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 1 ms 1900 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 1 ms 1900 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 2 ms 1900 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 2 ms 2028 KB Output is correct
17 Correct 3 ms 2028 KB Output is correct
18 Correct 2 ms 2028 KB Output is correct
19 Correct 2 ms 2028 KB Output is correct
20 Correct 2 ms 2028 KB Output is correct
21 Correct 3 ms 2156 KB Output is correct
22 Correct 3 ms 2156 KB Output is correct
23 Correct 6 ms 2668 KB Output is correct
24 Correct 6 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 1 ms 1900 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 1 ms 1900 KB Output is correct
8 Correct 1 ms 1900 KB Output is correct
9 Correct 1 ms 1900 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 1 ms 1900 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 2 ms 1900 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 2 ms 2028 KB Output is correct
17 Correct 3 ms 2028 KB Output is correct
18 Correct 2 ms 2028 KB Output is correct
19 Correct 2 ms 2028 KB Output is correct
20 Correct 2 ms 2028 KB Output is correct
21 Correct 3 ms 2156 KB Output is correct
22 Correct 3 ms 2156 KB Output is correct
23 Correct 6 ms 2668 KB Output is correct
24 Correct 6 ms 2668 KB Output is correct
25 Correct 5 ms 2668 KB Output is correct
26 Correct 9 ms 3456 KB Output is correct
27 Correct 9 ms 3308 KB Output is correct
28 Correct 43 ms 9196 KB Output is correct
29 Correct 46 ms 9196 KB Output is correct
30 Correct 116 ms 16492 KB Output is correct
31 Correct 104 ms 16364 KB Output is correct
32 Correct 105 ms 16364 KB Output is correct
33 Correct 84 ms 16364 KB Output is correct
34 Correct 95 ms 15980 KB Output is correct
35 Correct 112 ms 16400 KB Output is correct
36 Correct 93 ms 16364 KB Output is correct