이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* If you live in imaginary world when your imaginary situation encounter in
* real situation you can't enjoiy it because you have to do pending work.
* {This pending work appeared because you wasted that time for your useless
* imagianry thinking.}
*/
#include<bits/stdc++.h>
using namespace std;
//#define int int64_t
#define all(x) x.begin(),x.end()
#define all1(x) x.rbegin(),x.rend()
#define sz(x) x.size()
const int N=5e5+5;
int dp[2][2001];
priority_queue<int> q[2001];
void solve(){
int s,n;
cin>>s>>n;
for (int i=0,x,y,z;i<n;i++){
cin>>y>>x>>z;
int req=s/x;
for (int j=1;j<=min(req,z);j++){
q[x].push(y);
if (sz(q[x])>req){q[x].pop();}
}
}
int u(0);
int cur=1,prv=0;
for (int i=1;i<=s;i++){
while(!q[i].empty()){
u=q[i].top();
q[i].pop();
for (int j=1;j<=s;j++){
dp[cur][j]=dp[prv][j];
if (j>=i && dp[cur][j]<dp[prv][j-i]+u){
dp[cur][j]=dp[prv][j-i]+u;
}
}
swap(cur,prv);
}
}
int ans=0;
for (int i=1;i<=s;i++){ans=max(ans,dp[prv][i]);}
cout<<ans;
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
//freopen("feast.in","r",stdin);
//freopen("feast.out","w",stdout);
int tq=1;
//cin>>tq;
for (;tq;tq--){solve();}
}
//is a bruteforce possible?
//think greedier, make more assumptions
// if we you find solution using loop to decrease complexity use bs
//stuck for more than 5 minutes? move on
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'void solve()':
knapsack.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | if (sz(q[x])>req){q[x].pop();}
| ^
# | 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... |