This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
vii psh[M],pp[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;
}
}
}
}
cout<<ans<<'\n';
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) {
psh[l].pb(q.top());
pp[r].pb(q.top());
}
}
}
}
multiset<ll>s;
for(int i=0;i<n;i++) {
for(auto it:psh[i])
s.insert(it);
if(s.size()>0&&b[i]>=*s.begin())
cout<<1;
else
cout<<0;
for(auto it:pp[i])
s.erase(s.find(it));
}
return 0;
}
Compilation message (stderr)
trade.cpp: In function 'int main()':
trade.cpp:28: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]
28 | if(q.size()<k)
| ~~~~~~~~^~
trade.cpp:36: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]
36 | if(q.size()==k) {
| ~~~~~~~~^~~
trade.cpp:50: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]
50 | if(q.size()<k)
| ~~~~~~~~^~
trade.cpp:58: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]
58 | if(q.size()==k) {
| ~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |