# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1072147 | NeroZein | Tricks of the Trade (CEOI23_trade) | C++17 | 8079 ms | 3156 KiB |
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;
int main() {
int n, k;
cin >> n >> k;
vector<int> c(n), s(n);
for (int i = 0; i < n; ++i) {
cin >> c[i];
}
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
long long mx = -LLONG_MAX;
for (int i = 0; i < n; ++i) {
long long cost = 0;
for (int j = i; j < n; ++j) {
cost -= c[j];
multiset<int> se;
long long biggest = 0;
for (int kk = i; kk <= j; ++kk) {
biggest += s[kk];
se.insert(s[kk]);
if ((int) se.size() > k) {
biggest -= *se.begin();
se.erase(se.begin());
}
if (se.size() == k) {
mx = max(mx, cost + biggest);
}
}
}
}
vector<bool> ok(n);
for (int i = 0; i < n; ++i) {
long long cost = 0;
for (int j = i; j < n; ++j) {
cost -= c[j];
multiset<int> se;
long long biggest = 0;
for (int kk = i; kk <= j; ++kk) {
biggest += s[kk];
se.insert(s[kk]);
if ((int) se.size() > k) {
biggest -= *se.begin();
se.erase(se.begin());
}
}
if (cost + biggest == mx && se.size() == k) {
for (int kk = i; kk <= j; ++kk) {
if (s[kk] >= *se.begin()) {
ok[kk] = true;
}
}
}
}
}
cout << mx << '\n';
for (int i = 0; i < n; ++i) {
cout << ok[i];
}
}
Compilation message (stderr)
# | 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... |