이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 3e5 + 1;
int main(){
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int s, n; cin >> s >> n;
ll k[n + 1], v[n + 1], w[n + 1];
for(int i = 1; i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
}
ll dp[s + 1];
fill(dp, dp + s + 1, 0);
dp[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = s; j >= 0; j--){
ll cnt = -1;
for(int l = j; l >= 0; l -= w[i]){
cnt++;
if(cnt > k[i]) break;
dp[j] = max(dp[j], dp[l] + cnt * v[i]);
}
}
}
ll mx = 0;
for(int i = 1; i <= s; i++)
mx = max(mx, dp[i]);
cout << mx;
}
# | 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... |