이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define ROF(i,m,n) for(int i=m;i<=n;i++)
#define vi vector<int>
#define pb push_back
#define alle(a) a.begin(),a.end()
#define rall(n) rbegin(n),rend(n)
#define int long long
#define vecs vector<int>
#define ll long long
#define ss second
#define ff first
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 2005;
void solve() {
int s, n;
cin >> s >> n;
vector<int> dp(s + 1, 0);
for (int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
for (int b = 1; k > 0; b *= 2) {
int num = min(b, k);
k -= num;
int tv = num * v;
int tw = num * w;
for (int j = s; j >= tw; j--) {
dp[j] = max(dp[j], dp[j - tw] + tv);
}
}
}
cout << *max_element(dp.begin(), dp.end()) << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
# | 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... |