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;
int D[105][10005];
int ar[105][2];
int main()
{
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
int n, m; cin >> n >> m;
int sum = 0;
for(int i = 1; i <= n; i++)
cin >> ar[i][0];
for(int i = 1; i <= n; i++)
{
cin >> ar[i][1];
sum += ar[i][1];
}
for(int i = 1; i <= n; i++)
{
for(int j = 0; j <= sum; j++)
{
if(j - ar[i][1] < 0)
D[i][j] = D[i - 1][j];
else
D[i][j] = max(D[i - 1][j], D[i - 1][j - ar[i][1]] + ar[i][0]);
}
}
int ans = 0;
for(;D[n][ans] < m; ans++);
cout << ans;
}
# | 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... |