# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
322339 | saarang123 | Solar Storm (NOI20_solarstorm) | C++14 | 2050 ms | 262148 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;
using ll = long long;
const int MXN = 1e6 + 2;
ll dp[MXN][52];
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
int n, s, k;
cin >> n >> s >> k;
vector<ll> a(n + 1), d(n + 1);
vector<array<ll, 2>> c(n + 1);
for(int i = 1; i < n; i++) cin >> d[i];
for(int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1]; //prefix sums
vector<ll> p(n + 1);
for(int i = 1; i <= n; i++) p[i] = p[i - 1] + d[i - 1];
//cout << "prefix sums: ";
//for(int i = 1; i <= n; i++) cout << p[i] << ' '; cout << '\n';
for(int i = 1; i <= n; i++) {
int id = lower_bound(p.begin(), p.end(), p[i] + k) - p.begin();
if(id > n || p[id] > p[i] + k) id--;
//cout << id << ' ';
c[i][0] += a[id] - a[i];
c[i][1] = id + 1;
id = lower_bound(p.begin(), p.end(), p[i] - k) - p.begin();
c[i][0] += a[i] - a[id];
if(id) c[i][0] += a[id] - a[id - 1];
//cout << id << ' ' << c[i][0] << '\n';
}
for(int i = 1; i <= s; i++) dp[n][i] = a[n] - a[n - 1];
for(int i = n - 1; i; i--) {
for(int j = s; j; j--) {
int nxt = c[i][1];
dp[i][j] = c[i][0] + dp[nxt][j - 1];
}
}
//cout << "dp:\n";
//for(int i = 1; i <= n; i++) { for(int j = 0; j <= s; j++) cout << dp[i][j] << ' '; cout << '\n';}
ll ans = 0;
array<int, 2> best;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= s; j++) {
if(ans < dp[i][j]) ans = dp[i][j], best = {i, j};
}
}
vector<int> shield;
function<void(int i, int j)> out = [&] (int i, int j) {
if(j == 0) return;
shield.push_back(i);
out(c[i][1], j - 1);
};
out(best[0], best[1]);
//cout << ans << '\n';
cout << shield.size() << '\n';
for(int x : shield) cout << x << ' '; cout << '\n';
return 0;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |