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;
#define ar array
#define int long long
#define ld long double
const int N = 1e6 + 20;
const int X = 5e5 + 20;
const int LOG = 21;
const int INF = 1e17;
signed main(){ios::sync_with_stdio(false);cin.tie(0);
int n, m;
cin>>n>>m;
vector<int> v;
for(int i = -n;i <= n;i++){
int x;
cin>>x;
for(int j = 0;j < x;j++)v.push_back(i);
}
map<int,int> dp;
dp[0] = 0;
for(auto u: v){
map<int, int> ndp = dp;
for(auto [a, b]: dp){
ndp[a + u] = max(ndp[a + u], b + 1);
}
dp = ndp;
}
if(dp.count(m))cout<<dp[m];
else cout<<"impossible";
}
# | 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... |