# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
883822 | PieArmy | Knapsack (NOI18_knapsack) | C++14 | 1 ms | 616 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define yem(re) (1ll<<(ll(re)))
#define endl '\n'
#define pb push_back
#define int long long
#define mid ((left+right)/2)
#define L(emanuelLasker,joseRaulCapablanca,anatolyKarpov) for(int emanuelLasker=(joseRaulCapablanca);emanuelLasker<=(anatolyKarpov);emanuelLasker++)
#define R(magnusCarlsen,paulMorphy,bobbyFischer) for(int magnusCarlsen=(paulMorphy);magnusCarlsen>=(bobbyFischer);magnusCarlsen--)
#define cint(vladimirKramnik) int vladimirKramnik;cin>>vladimirKramnik
#define inf (2e18+5)
#define sc second
#define fr first
#define Bismillahirrahmanirrahim ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cinarr(mikhailTal) for(auto &garryKasparov:mikhailTal)cin>>garryKasparov;
#define all(mustafaKemalAtaturk) mustafaKemalAtaturk.begin(),mustafaKemalAtaturk.end()
using namespace std;
mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count());
void code(){
int n,k;cin>>k>>n;
vector<pair<int,pair<int,int>>>v;
L(i,0,n-1){
cint(val);cint(cos);cint(num);
v.pb({val,{cos,num}});
}
sort(all(v));
vector<int>dp(k+1,-1);
dp[0]=0;
R(i,n-1,0){
vector<int>dp2(k+1,-1);
int val=v[i].fr,cos=v[i].sc.fr,num=v[i].sc.sc;
L(j,0,k)dp2[i]=dp[i];
L(j,0,k){
if(dp[j]==-1)continue;
int x=min(ll((k-j)/cos),num);
dp2[j+(x*cos)]=max(dp2[j+(x*cos)],dp[j]+(x*val));
}
swap(dp2,dp);
}
int ans=0;
for(int x:dp)ans=max(x,ans);
cout<<ans;
}
int32_t main(){
Bismillahirrahmanirrahim
int t=1;
bool usaco=0;
if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
if(!t)cin>>t;
while(t--){code();cout<<endl;}
return 0;
}
//Haven't checked tutorial yet...
컴파일 시 표준 에러 (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... |