# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721891 | sunnat | Uplifting Excursion (BOI22_vault) | C++14 | 6 ms | 2516 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 <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
int main(){
vector<int> dp[2];
int n, m, res = -1;
cin >> n >> m;
vector<int>a(2*n+1);
int q = 65000;
for(int i = 0; i < a.size(); i ++)
cin >> a[i];
dp[1].resize(2*q+1, -1);
dp[1][q] = 0;
for(int val = -n; val <= n; val ++){
// cout << val << endl;
if(val == 0) continue;
dp[0] = dp[1];
int v = val + n;
for(int cnt = 1; cnt <= a[v]; cnt ++){
for(int sum = -q; sum <= q; sum ++){
if(dp[1][sum+q] != -1)
if(-q <= sum+val*cnt && sum+val*cnt <= q)
dp[0][sum+val*cnt+q] = max(dp[0][sum+val*cnt+q], dp[1][sum+q] + cnt);
}
}
dp[1] = dp[0];
}
if(dp[1][m+q] != -1)
cout << dp[1][m+q] + a[n];
else
cout << "impossible";
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |