# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
659019 | smirichto | Knapsack (NOI18_knapsack) | C++17 | 1 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
STAY ORGANIZED
CHANGE YOUR APPROACH
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef long double ld ;
#define FAST ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
#define pb push_back
#define pi pair<ll , ll>
#define pll pair<ll,ll>
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define fr(i,a,b) for(ll i = a;i < (ll)b;i++)
#define rfr(i,a,b) for(ll i = a;i > (ll)b;i--)
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define alll(x) ((x).begin()+1), (x).end()
#define MOD 998244353
#define endl '\n'
const ll mod = 1e9+7 ;
void io(string s = "" ,bool flag = 0){
ios::sync_with_stdio(false) ;cin.tie(NULL) ;
if(s.size()) {
freopen((s + ".in").c_str(),"r",stdin) ;
if(flag) freopen((s + ".out").c_str(),"w",stdout) ;
}
}
void dbg(vector<ll> tab){for(auto it : tab) cout<<it<<" ";cout<<endl;}
void dbgg(pi p){cout<<p.F<<" "<<p.S<<endl;}
void dbgpi(vector<pi> tab){for(auto it : tab) dbgg(it) ;}
template<class T> bool ckmax(T& a, const T& b){return a < b ? a = b, 1 : 0;}
template<class T> bool ckmin(T& a, const T& b){return a > b ? a = b, 1 : 0;}
template<class T> void add(T& a, const T& b){a = a + b ; if(a>mod) a-= mod ;}
void nop(){cout<<-1<<endl;return;}
const ll inf = 1e9 ;
const ll N = 1e5+5 ;
ll s , n , val[N] , weight[N] , k[N] ;
pi dp1[2005] , dp2[2005] ;
void solve()
{
cin>>s>>n ;
for(ll i = 1 ; i<=n ; i++){
cin>>val[i]>>weight[i]>>k[i] ;
}
ll ans = 0 ;
for(ll i = 1 ; i<=n ; i++){
for(ll j = 1 ; j<s+1 ; j++){
dp1[j].first = dp2[j].first ;
if(j<weight[i] || dp1[j-weight[i]].second>=k[i]) continue ;
if(dp1[j-weight[i]].first+val[i]>dp1[j].first){
dp1[j].first = dp1[j-weight[i]].first+val[i] ;
dp1[j].second = dp1[j-weight[i]].second + 1 ;
}
}
for(ll j = 0 ; j<s+1 ; j++){
dp2[j] = dp1[j] ;
dp1[j].second = 0 ;
ckmax(ans , dp1[j].first) ;
}
}
cout<<ans<<endl;
}
int main()
{
io() ;
srand(time(0)) ;
ll tt = 1 ;
// cin>>tt ;
for(ll i = 1 ; i<=tt ; i++){
solve() ;
}
}
컴파일 시 표준 에러 (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... |