이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a))
#define boost() ios_base::sync_with_stdio(false); cin.tie(); cout.tie()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int mxN=2e3+5;
vector <pll> withw[mxN];
ll dp[mxN][mxN]={};
int main(){
ll s, n;
cin >> s >> n;
for(int i=0; i<n; i++){
ll v, w, k;
cin >> v >> w >> k;
withw[w].push_back(MP(v, k));
}
for(int i=1; i<=2000; i++){
sort(withw[i].begin(), withw[i].end());
for(int j=1; j<=s; j++){
dp[i][j] = dp[i-1][j];
ll totalval=0, totalw=0;
for(auto [val, amnt]:withw[i]){
ll temp=1;
while(temp <= amnt && j >= totalw){
totalval+=val;
totalw+=i;
dp[i][j] = max(dp[i][j], dp[i-1][j-totalw]+totalval);
temp++;
}
}
}
}
cout << dp[2000][s];
}
# | 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... |