#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll n, k, ans = -1e18;
cin >> n >> k;
vll b(n), s(n);
for (ll i = 0; i < n; ++i)
cin >> b[i];
for (ll i = 0; i < n; ++i)
cin >> s[i];
vll in(n), res(n);
for (ll st = 0; st < n; ++st) {
ll sum_buy = 0;
priority_queue<pll, vector<pll>, greater<pll>> pq;
ll sum_pq = 0;
in.assign(n, 0);
for (ll ed = st; ed < n; ++ed) {
sum_buy += b[ed];
pq.push({s[ed], ed});
in[ed] = 1;
sum_pq += s[ed];
while (pq.size() > k) {
auto [node, idx] = pq.top();
pq.pop();
sum_pq -= node;
in[idx] = 0;
}
if (pq.size() == k) {
ll ans_ed = sum_pq - sum_buy;
if (ans < ans_ed) {
ans = ans_ed;
res = in;
}
if (ans == ans_ed) {
ans = ans_ed;
for (ll i = 0; i < n; ++i)
if (in[i] == 1)
res[i] = 1;
}
}
}
}
cout << ans << endl;
string ss(n, '0');
for (ll i = 0; i < n; ++i)
if (res[i] == 1)
ss[i] = '1';
cout << ss << endl;
return 0;
}
| # | 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... |