Submission #224690

#TimeUsernameProblemLanguageResultExecution timeMemory
224690Haunted_CppSolar Storm (NOI20_solarstorm)C++17
28 / 100
2084 ms28792 KiB
#include <iostream> #include <vector> #include <algorithm> #include <bitset> #include <cassert> typedef long long i64; using namespace std; const int N = 1e6 + 5; int dist [N], valor [N]; int jump [N]; vector<i64> sum; vector<i64> dp; bitset<N> has_shield; int main () { ios::sync_with_stdio(0); cin.tie(0); int n, s; i64 k; cin >> n >> s >> k; sum.resize(n); dp.resize(n); for (int i = 0; i < n - 1; i++) { cin >> dist[i]; if (i) { sum[i] = sum[i - 1] + dist[i - 1]; } } sum[n - 1] = (n - 2 >= 0 ? sum[n - 2] + dist[n - 2] : 0); for (int i = 0; i < n; i++) { cin >> valor[i]; dp[i] += valor[i]; if (i) dp[i] += dp[i - 1]; } i64 mx = -1; int best_start = -1; for (int i = 0; i < n; i++) { jump[i] = upper_bound (sum.begin(), sum.end(), sum[i] + k) - sum.begin(); } for (int i = 0; i < n; i++) { i64 cur = 0; int shield_left = s; int p = (lower_bound (sum.begin(), sum.end(), sum[i] - k) - sum.begin()); cur += (dp[i] - (p - 1 >= 0 ? dp[p - 1] : 0)) - valor[i]; for (int hi = i; shield_left > 0; ) { if (hi >= n) break; --shield_left; int nxt = jump[hi]; cur += (nxt - 1 >= 0 ? dp[nxt - 1] : 0) - (hi - 1 >= 0 ? dp[hi - 1] : 0); hi = nxt; } if (cur > mx) { mx = cur; best_start = i; } } vector<int> ans; int shield_left = s; for (int hi = best_start; shield_left > 0; ) { if (hi >= n) break; --shield_left; ans.emplace_back(hi); hi = jump[hi]; } cout << (int) ans.size() << '\n'; for (auto to : ans) cout << to + 1 << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...