이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/////////////////////////////////////////////////////////////////
//////// Born_To_Laugh - Hughie Do ////////
/////////////////////////////////////////////////////////////////
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAXN=3e5+5;
const int INF=1e9+7;
/*
Idea:
*/
void solve(){
int t ,s;
cin >> s >> t;
vector<pair<int,int>> items;
items.push_back({0,0});
int n=0;
while(t--){
int w, v ,k;
cin >> v >> w >> k;
if(w<=s){
n+=k;
while(k--){
items.push_back({w,v});
}
}
}
sort(items.begin(), items.end());
vector<vector<int>> dp(n+1, vector<int> (s+1, 0));
/*
dp[i][j]=max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
*/
dp[0][0]=0;
for(int i=1; i<=n; ++i){
for(int j=0; j<=s; ++j){
if(j-items[i].first >= 0){
dp[i][j]=max(dp[i-1][j], dp[i-1][j-items[i].first] + items[i].second);
}
else{
dp[i][j]=dp[i-1][j];
}
}
}
cout << dp[n][s];
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
solve();
return 0;
}
# | 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... |