# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588637 | peuch | Uplifting Excursion (BOI22_vault) | C++17 | 0 ms | 212 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;
const int MAXN = 610;
const long long INF = 1e18;
int m;
long long l;
long long aux[MAXN];
long long *v = aux + 300;
int main(){
scanf("%d %lld", &m, &l);
for(int i = -m; i <= m; i++)
scanf("%lld", &v[i]);
long long sum = 0;
long long cnt = 0;
for(int i = 1; i <= m; i++){
if(sum + v[i] * i <= l){
sum += v[i] * i;
cnt += v[i];
continue;
}
cnt += ((l - sum) / i + 1);
sum += i * ((l - sum) / i + 1);
}
if(sum < l){
printf("impossible\n");
return 0;
}
vector<long long> dp(sum - l + 1, INF);
dp[0] = 0;
vector<int> moedas;
for(int i = 1; i <= m; i++){
for(int j = 0; j < min(300LL, v[i]); j++)
moedas.push_back(i);
}
for(int i = 0; i < moedas.size(); i++){
for(int j = moedas[i]; j < dp.size(); j++){
dp[j] = min(dp[j], dp[j - moedas[i]] + 1);
}
}
if(dp.back() == INF) printf("impossible\n");
else printf("%lld\n", v[0] + cnt - dp.back());
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |