Submission #340408

#TimeUsernameProblemLanguageResultExecution timeMemory
340408apostoldaniel854Solar Storm (NOI20_solarstorm)C++14
100 / 100
395 ms122716 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define dbg(x) cerr << #x << " " << x << "\n" const int LG = 20, MAX_N = 1e6; int p[LG][1 + MAX_N]; int nxt[1 + MAX_N]; ll sumd[1 + MAX_N], sumv[1 + MAX_N]; int n; void lift () { for (int k = 1; k < LG; k++) for (int i = 1; i <= n; i++) p[k][i] = p[k - 1][p[k - 1][i]]; } int main () { ios::sync_with_stdio (false); cin.tie (0); cout.tie (0); int s; ll k; cin >> n >> s >> k; s--; for (int i = 2; i <= n; i++) { cin >> sumd[i]; sumd[i] += sumd[i - 1]; } for (int i = 1; i <= n; i++) { cin >> sumv[i]; sumv[i] += sumv[i - 1]; } int a = 1, b = 1; for (int i = 1; i <= n; i++) { while (a <= n && sumd[a] - sumd[i] <= k) a++; while (b <= n && sumd[b] - sumd[a] <= k) b++; nxt[i] = a - 1; p[0][i] = b - 1; } lift (); ll bestsum = 0; int bestid = 0, j = 1; for (int i = 1; i <= n; i++) { while (sumd[i] - sumd[j] > k) j++; int cur = i; for (int bit = LG - 1; bit >= 0; bit--) if ((1 << bit) & s) cur = p[bit][cur]; cur = nxt[cur]; if (bestsum < sumv[cur] - sumv[j - 1]) { bestsum = sumv[cur] - sumv[j - 1]; bestid = i; } } vector <int> sol; while (bestid && s >= 0) { sol.pb (bestid); bestid = p[0][bestid]; s--; } cout << sol.size () << "\n"; for (int x : sol) cout << x << " "; cout << "\n"; 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...