#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=6e3+10;
const ll inf=2e18;
ll n,k,a[M],b[M],c[M];
int main() {
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
ll ans=-inf;
ll l,r;
for(int i=0;i<n;i++) {
ll nsum=0,psum=0;
priority_queue<ll,vii,greater<ll>>q;
for(int j=i;j<n;j++) {
nsum+=a[j];
if(q.size()<k)
q.push(b[j]),psum+=b[j];
else {
if(b[j]<q.top())
continue;
else
psum-=q.top(),q.pop(),q.push(b[j]),psum+=b[j];
}
if(q.size()==k) {
if(ans<psum-nsum) {
ans=max(ans,psum-nsum);
l=i,r=j;
}
}
}
}
ll cur=0;
ans=0;
for(int i=l;i<=r;i++)
ans-=a[i];
for(int j=0;j<k;j++) {
cur=0;
ll ind=0;
for(int i=l;i<=r;i++) {
if(b[i]>=cur)
cur=b[i],ind=i;
}
ans+=b[ind],b[ind]=-1;
}
cout<<ans<<'\n';
for(int i=0;i<n;i++) {
if(b[i]==-1)
cout<<1;
else
cout<<0;
}
return 0;
}
Compilation message
trade.cpp: In function 'int main()':
trade.cpp:27:24: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
27 | if(q.size()<k)
| ~~~~~~~~^~
trade.cpp:35:24: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
35 | if(q.size()==k) {
| ~~~~~~~~^~~
trade.cpp:21:10: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
21 | ll l,r;
| ^
trade.cpp:45:13: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
45 | for(int i=l;i<=r;i++)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Partially correct |
1 ms |
348 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Partially correct |
0 ms |
464 KB |
Partially correct |
3 |
Partially correct |
0 ms |
348 KB |
Partially correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Partially correct |
1 ms |
344 KB |
Partially correct |
7 |
Partially correct |
1 ms |
348 KB |
Partially correct |
8 |
Partially correct |
0 ms |
348 KB |
Partially correct |
9 |
Partially correct |
1 ms |
344 KB |
Partially correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Partially correct |
1 ms |
348 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Partially correct |
0 ms |
464 KB |
Partially correct |
3 |
Partially correct |
0 ms |
348 KB |
Partially correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Partially correct |
1 ms |
344 KB |
Partially correct |
7 |
Partially correct |
1 ms |
348 KB |
Partially correct |
8 |
Partially correct |
0 ms |
348 KB |
Partially correct |
9 |
Partially correct |
1 ms |
344 KB |
Partially correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Partially correct |
1 ms |
348 KB |
Partially correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Partially correct |
0 ms |
348 KB |
Partially correct |
14 |
Partially correct |
0 ms |
348 KB |
Partially correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
18 |
Partially correct |
1 ms |
348 KB |
Partially correct |
19 |
Partially correct |
0 ms |
348 KB |
Partially correct |
20 |
Partially correct |
1 ms |
760 KB |
Partially correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Partially correct |
1 ms |
348 KB |
Partially correct |
23 |
Correct |
360 ms |
724 KB |
Output is correct |
24 |
Partially correct |
44 ms |
604 KB |
Partially correct |
25 |
Partially correct |
513 ms |
600 KB |
Partially correct |
26 |
Partially correct |
361 ms |
604 KB |
Partially correct |
27 |
Partially correct |
230 ms |
600 KB |
Partially correct |
28 |
Correct |
32 ms |
348 KB |
Output is correct |
29 |
Correct |
470 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Partially correct |
2 |
Runtime error |
1 ms |
732 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Partially correct |
2 |
Runtime error |
1 ms |
732 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Partially correct |
1 ms |
348 KB |
Partially correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Partially correct |
0 ms |
464 KB |
Partially correct |
5 |
Partially correct |
0 ms |
348 KB |
Partially correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Partially correct |
1 ms |
344 KB |
Partially correct |
9 |
Partially correct |
1 ms |
348 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Partially correct |
1 ms |
344 KB |
Partially correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Partially correct |
1 ms |
348 KB |
Partially correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Partially correct |
0 ms |
348 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Partially correct |
0 ms |
348 KB |
Partially correct |
20 |
Partially correct |
1 ms |
348 KB |
Partially correct |
21 |
Partially correct |
0 ms |
348 KB |
Partially correct |
22 |
Partially correct |
1 ms |
760 KB |
Partially correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Partially correct |
1 ms |
348 KB |
Partially correct |
25 |
Correct |
360 ms |
724 KB |
Output is correct |
26 |
Partially correct |
44 ms |
604 KB |
Partially correct |
27 |
Partially correct |
513 ms |
600 KB |
Partially correct |
28 |
Partially correct |
361 ms |
604 KB |
Partially correct |
29 |
Partially correct |
230 ms |
600 KB |
Partially correct |
30 |
Correct |
32 ms |
348 KB |
Output is correct |
31 |
Correct |
470 ms |
652 KB |
Output is correct |
32 |
Partially correct |
0 ms |
348 KB |
Partially correct |
33 |
Runtime error |
1 ms |
732 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |