Submission #721712

#TimeUsernameProblemLanguageResultExecution timeMemory
721712dxz05Uplifting Excursion (BOI22_vault)C++17
0 / 100
1 ms212 KiB
#pragma GCC optimize("Ofast,O3,unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() #define MP make_pair const int N = 100500; long long solve(){ int m; ll L; cin >> m >> L; if (L < 0) return -1; vector<ll> a(m + 1); vector<int> b; for (int i = -m; i <= m; i++){ ll x; cin >> x; if (i < 0) continue; a[i] = x; if (i > 0) { ll mn = min((ll) 2 * m / i, a[i]); while (mn--) b.push_back(i); } } const int LIM = accumulate(all(b), 0) + 1; vector<int> dp(LIM, 1e9); dp[0] = 0; for (int x : b) { for (int i = LIM - 1; i >= x; i--) { dp[i] = min(dp[i], dp[i - x] + 1); } } if (L == 0) return a[0]; ll ans = -1; ll tot = 0, cnt = a[0]; for (int i = 1; i <= m; i++){ assert(tot <= L); ll x = min(a[i], (L - tot) / i); tot += x * i; cnt += x; if (tot == L){ ans = max(ans, cnt); } else if (a[i] > x){ ll del = tot + i - L; if (del < LIM) ans = max(ans, cnt - dp[del] + 1); } } return ans; } int main() { ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif long long result = solve(); if (result != -1){ cout << result << endl; } else { cout << "impossible" << endl; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...