이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e5 + 1;
ll dp[2001];
void solve() {
int s, n;
cin >> s >> n;
vt<pii> hv[2001];
for(int i = 0, v, w, k; i < n; i++){
cin >> v >> w >> k;
k = min(k, s / w);
hv[w].pb({v, k});
}
for(int i = 1; i <= s; i++){
sort(rall(hv[i]));
int cnt = 0;
for(size_t j = 0; j < hv[i].size(); j++){
while(hv[i][j].ss--){
for(int o = s; o >= i; o--){
dp[o] = max(dp[o - i] + hv[i][j].ff, dp[o]);
}
cnt++;
if(cnt * i >= s)break;
}
if(cnt * i >= s)break;
}
}
cout << dp[s];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
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... |