# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1247788 | fadyy287 | Knapsack (NOI18_knapsack) | C++20 | 48 ms | 2884 KiB |
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define endl "\n"
#define map unordered_map
typedef long long ll;
typedef long double ld;
void test(){
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
int main(){
//test();
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll s,n;
cin>>s>>n;
vector<pair<ll,ll>> weight[s+1];
for(ll i=0;i<n;++i){
ll v,w,k;
cin>>v>>w>>k;
if(w<=s && k) weight[w].push_back({v,k});
}
ll dp[s+1]{};
for(ll i=1;i<=s;++i){
sort(weight[i].rbegin(),weight[i].rend());
for(ll j=s;j>=1;--j){
ll num=0;
ll got=0;
ll ww=0;
ll value=0;
ll pos=0;
while(ww<=j-i){
if(pos==weight[i].size()) break;
if(got==weight[i][pos].second){
got=0;
pos++;
continue;
}
value+=weight[i][pos].first;
ww+=i;
got++;
dp[j]=max(dp[j],dp[j-ww]+value);
//cout<<i<<" "<<j<<" "<<dd[j]<<" "<<got<<" "<<pos<<endl;
}
}
}
cout<<dp[s];
}
컴파일 시 표준 에러 (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... |