# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1040760 | 2024-08-01T09:01:13 Z | 정희우(#10998) | Tricks of the Trade (CEOI23_trade) | C++17 | 8000 ms | 3748 KB |
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; using lint = long long; using intp = pair<int,int>; using vint = vector<int>; const int MAX_N=250010; const int MAX_K=6010; const lint INF=1e+9*MAX_N; int n,k; int c[MAX_N],p[MAX_N]; priority_queue<int,vint,greater<int>> pq; lint lv[MAX_K],rv[MAX_K]; lint ans; int check[MAX_K]; int possi[MAX_N]; void calc(int s,int e) { if(e-s<k)return; int m=(s+e)>>1; fill(lv,lv+MAX_K,-INF); fill(rv,rv+MAX_K,-INF); lv[0]=rv[0]=0; for(int i=1;i<=k;i++) { lint cnt=0; for(int j=m-1;j>=s;j--) { cnt+=p[j]-c[j]; pq.push(p[j]); while(!pq.empty() && pq.size()>i) { cnt-=pq.top(); pq.pop(); } if(!pq.empty() && pq.size()==i) lv[i]=max(lv[i],cnt); } while(!pq.empty())pq.pop(); cnt=0; for(int j=m;j<e;j++) { cnt+=p[j]-c[j]; pq.push(p[j]); while(!pq.empty() && pq.size()>i) { cnt-=pq.top(); pq.pop(); } if(!pq.empty() && pq.size()==i) rv[i]=max(rv[i],cnt); } while(!pq.empty())pq.pop(); } for(int i=0;i<=k;i++) ans=max(ans,lv[i]+rv[k-i]); calc(s,m); calc(m,e); } void bt(int s,int e) { if(e-s<k)return; int m=(s+e)>>1; fill(lv,lv+MAX_K,-INF); fill(rv,rv+MAX_K,-INF); lv[0]=rv[0]=0; for(int i=1;i<=k;i++) { lint cnt=0; for(int j=m-1;j>=s;j--) { cnt+=p[j]-c[j]; pq.push(p[j]); while(!pq.empty() && pq.size()>i) { cnt-=pq.top(); pq.pop(); } if(!pq.empty() && pq.size()==i) lv[i]=max(lv[i],cnt); } while(!pq.empty())pq.pop(); cnt=0; for(int j=m;j<e;j++) { cnt+=p[j]-c[j]; pq.push(p[j]); while(!pq.empty() && pq.size()>i) { cnt-=pq.top(); pq.pop(); } if(!pq.empty() && pq.size()==i) rv[i]=max(rv[i],cnt); } while(!pq.empty())pq.pop(); } fill(check,check+MAX_K,0); for(int i=0;i<=k;i++) if(lv[i]+rv[k-i]==ans)check[i]=1; for(int i=1;i<=k;i++) { lint cnt=0; int pl=m-1,pr=m; for(int j=m-1;j>=s;j--) { cnt+=p[j]-c[j]; pq.push(p[j]); while(!pq.empty() && pq.size()>i) { cnt-=pq.top(); pq.pop(); } if(!pq.empty() && pq.size()==i && cnt==lv[i] && check[i]) while(pl>=j) { if(p[pl]>=pq.top())possi[pl]=1; pl--; } } while(!pq.empty())pq.pop(); cnt=0; for(int j=m;j<e;j++) { cnt+=p[j]-c[j]; pq.push(p[j]); while(!pq.empty() && pq.size()>i) { cnt-=pq.top(); pq.pop(); } if(!pq.empty() && pq.size()==i && cnt==rv[i] && check[k-i]) while(pr<=j) { if(p[pr]>=pq.top())possi[pr]=1; pr++; } } while(!pq.empty())pq.pop(); } bt(s,m); bt(m,e); } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> k; for(int i=0;i<n;i++) cin >> c[i]; for(int i=0;i<n;i++) cin >> p[i]; ans=-INF; calc(0,n); bt(0,n); cout << ans << '\n'; for(int i=0;i<n;i++) cout << possi[i]; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Correct | 3 ms | 2396 KB | Output is correct |
5 | Correct | 2 ms | 2520 KB | Output is correct |
6 | Correct | 2 ms | 2396 KB | Output is correct |
7 | Correct | 2 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2396 KB | Output is correct |
9 | Correct | 2 ms | 2396 KB | Output is correct |
10 | Correct | 2 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Correct | 3 ms | 2396 KB | Output is correct |
5 | Correct | 2 ms | 2520 KB | Output is correct |
6 | Correct | 2 ms | 2396 KB | Output is correct |
7 | Correct | 2 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2396 KB | Output is correct |
9 | Correct | 2 ms | 2396 KB | Output is correct |
10 | Correct | 2 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 2396 KB | Output is correct |
12 | Correct | 0 ms | 2396 KB | Output is correct |
13 | Correct | 0 ms | 2516 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 3 ms | 2396 KB | Output is correct |
16 | Correct | 4 ms | 2396 KB | Output is correct |
17 | Correct | 2 ms | 2396 KB | Output is correct |
18 | Correct | 2 ms | 2512 KB | Output is correct |
19 | Correct | 2 ms | 2392 KB | Output is correct |
20 | Correct | 2 ms | 2396 KB | Output is correct |
21 | Correct | 2 ms | 2396 KB | Output is correct |
22 | Correct | 2 ms | 2396 KB | Output is correct |
23 | Correct | 5501 ms | 2772 KB | Output is correct |
24 | Correct | 46 ms | 2396 KB | Output is correct |
25 | Correct | 1772 ms | 2392 KB | Output is correct |
26 | Correct | 243 ms | 2396 KB | Output is correct |
27 | Correct | 1217 ms | 2508 KB | Output is correct |
28 | Correct | 66 ms | 2396 KB | Output is correct |
29 | Correct | 4967 ms | 2520 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 2876 ms | 3748 KB | Output is correct |
3 | Correct | 2844 ms | 3568 KB | Output is correct |
4 | Correct | 2878 ms | 3568 KB | Output is correct |
5 | Correct | 2777 ms | 3668 KB | Output is correct |
6 | Correct | 2809 ms | 3572 KB | Output is correct |
7 | Correct | 2907 ms | 3588 KB | Output is correct |
8 | Correct | 2831 ms | 3572 KB | Output is correct |
9 | Correct | 2922 ms | 3576 KB | Output is correct |
10 | Correct | 2925 ms | 3740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 2876 ms | 3748 KB | Output is correct |
3 | Correct | 2844 ms | 3568 KB | Output is correct |
4 | Correct | 2878 ms | 3568 KB | Output is correct |
5 | Correct | 2777 ms | 3668 KB | Output is correct |
6 | Correct | 2809 ms | 3572 KB | Output is correct |
7 | Correct | 2907 ms | 3588 KB | Output is correct |
8 | Correct | 2831 ms | 3572 KB | Output is correct |
9 | Correct | 2922 ms | 3576 KB | Output is correct |
10 | Correct | 2925 ms | 3740 KB | Output is correct |
11 | Correct | 1 ms | 2396 KB | Output is correct |
12 | Correct | 2953 ms | 3572 KB | Output is correct |
13 | Correct | 3063 ms | 3572 KB | Output is correct |
14 | Correct | 3023 ms | 3568 KB | Output is correct |
15 | Correct | 3076 ms | 3576 KB | Output is correct |
16 | Correct | 2865 ms | 3668 KB | Output is correct |
17 | Correct | 2882 ms | 3664 KB | Output is correct |
18 | Correct | 2854 ms | 3580 KB | Output is correct |
19 | Correct | 2832 ms | 3408 KB | Output is correct |
20 | Correct | 2922 ms | 3740 KB | Output is correct |
21 | Correct | 1 ms | 2392 KB | Output is correct |
22 | Correct | 0 ms | 2392 KB | Output is correct |
23 | Correct | 3 ms | 2396 KB | Output is correct |
24 | Correct | 2 ms | 2396 KB | Output is correct |
25 | Correct | 2 ms | 2396 KB | Output is correct |
26 | Correct | 2 ms | 2396 KB | Output is correct |
27 | Correct | 1 ms | 2396 KB | Output is correct |
28 | Correct | 2 ms | 2396 KB | Output is correct |
29 | Correct | 2 ms | 2396 KB | Output is correct |
30 | Correct | 1 ms | 2396 KB | Output is correct |
31 | Execution timed out | 8098 ms | 3316 KB | Time limit exceeded |
32 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 0 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 3 ms | 2396 KB | Output is correct |
7 | Correct | 2 ms | 2520 KB | Output is correct |
8 | Correct | 2 ms | 2396 KB | Output is correct |
9 | Correct | 2 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 2 ms | 2396 KB | Output is correct |
12 | Correct | 2 ms | 2396 KB | Output is correct |
13 | Correct | 1 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 0 ms | 2516 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 3 ms | 2396 KB | Output is correct |
18 | Correct | 4 ms | 2396 KB | Output is correct |
19 | Correct | 2 ms | 2396 KB | Output is correct |
20 | Correct | 2 ms | 2512 KB | Output is correct |
21 | Correct | 2 ms | 2392 KB | Output is correct |
22 | Correct | 2 ms | 2396 KB | Output is correct |
23 | Correct | 2 ms | 2396 KB | Output is correct |
24 | Correct | 2 ms | 2396 KB | Output is correct |
25 | Correct | 5501 ms | 2772 KB | Output is correct |
26 | Correct | 46 ms | 2396 KB | Output is correct |
27 | Correct | 1772 ms | 2392 KB | Output is correct |
28 | Correct | 243 ms | 2396 KB | Output is correct |
29 | Correct | 1217 ms | 2508 KB | Output is correct |
30 | Correct | 66 ms | 2396 KB | Output is correct |
31 | Correct | 4967 ms | 2520 KB | Output is correct |
32 | Correct | 1 ms | 2392 KB | Output is correct |
33 | Correct | 2876 ms | 3748 KB | Output is correct |
34 | Correct | 2844 ms | 3568 KB | Output is correct |
35 | Correct | 2878 ms | 3568 KB | Output is correct |
36 | Correct | 2777 ms | 3668 KB | Output is correct |
37 | Correct | 2809 ms | 3572 KB | Output is correct |
38 | Correct | 2907 ms | 3588 KB | Output is correct |
39 | Correct | 2831 ms | 3572 KB | Output is correct |
40 | Correct | 2922 ms | 3576 KB | Output is correct |
41 | Correct | 2925 ms | 3740 KB | Output is correct |
42 | Correct | 1 ms | 2396 KB | Output is correct |
43 | Correct | 2953 ms | 3572 KB | Output is correct |
44 | Correct | 3063 ms | 3572 KB | Output is correct |
45 | Correct | 3023 ms | 3568 KB | Output is correct |
46 | Correct | 3076 ms | 3576 KB | Output is correct |
47 | Correct | 2865 ms | 3668 KB | Output is correct |
48 | Correct | 2882 ms | 3664 KB | Output is correct |
49 | Correct | 2854 ms | 3580 KB | Output is correct |
50 | Correct | 2832 ms | 3408 KB | Output is correct |
51 | Correct | 2922 ms | 3740 KB | Output is correct |
52 | Correct | 1 ms | 2392 KB | Output is correct |
53 | Correct | 0 ms | 2392 KB | Output is correct |
54 | Correct | 3 ms | 2396 KB | Output is correct |
55 | Correct | 2 ms | 2396 KB | Output is correct |
56 | Correct | 2 ms | 2396 KB | Output is correct |
57 | Correct | 2 ms | 2396 KB | Output is correct |
58 | Correct | 1 ms | 2396 KB | Output is correct |
59 | Correct | 2 ms | 2396 KB | Output is correct |
60 | Correct | 2 ms | 2396 KB | Output is correct |
61 | Correct | 1 ms | 2396 KB | Output is correct |
62 | Execution timed out | 8098 ms | 3316 KB | Time limit exceeded |
63 | Halted | 0 ms | 0 KB | - |