# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
808815 | GoldLight | Knapsack (NOI18_knapsack) | C++17 | 2 ms | 240 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;
void fast(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=2e3;
long long dp[N+1];
int main(){
fast();
int s, n, v, w, k; cin>>s>>n;
for(int i=1; i<=n; i++){
cin>>v>>w>>k;
for(int j=s; j>=1; j--){
int ki=1, ka=k, ans=0;
while(ki<=ka){
int mid=(ki+ka)/2;
if(1ll*w*mid<=1ll*j){
dp[j]=max(dp[j], dp[j-w*mid]+v*mid);
ki=mid+1;
}
else ka=mid-1;
}
}
}
cout<<dp[s];
}
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... |