이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <cstdio>
#include <ext/pb_ds/assoc_container.hpp>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define pb push_back
#define all(x) begin(x), end(x)
#define umap unordered_map
#define space " "
#define TEST_CASES int a; cin >> a; for (int i = 0; i < a; i++) {solve(); cout << endl;}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct cow{
ll l, r, w;
};
void solve() {
int b, c; cin >> b >> c;
vector<cow> vec(c);
for (int i = 0; i < c; i++){
cin >> vec[i].l >> vec[i].r >> vec[i].w;
}
vector<ll> dp(b + 1, -1);
dp[0] = 0;
umap<int, vector<int>> curr;
curr[0] = vector<int>(c, 0);
ll res = 0;
for (int i = 1; i <= b; i++){
ll mx = -1; int ind = -1;
for (int j = 0; j < c; j++){
if (i - vec[j].r >= 0 && dp[i - vec[j].r] != -1 && curr[i - vec[j].r][j] < vec[j].w && dp[i - vec[j].r] + vec[j].l > mx){
mx = dp[i - vec[j].r] + vec[j].l;
ind = j;
}
}
if (ind != -1) {
dp[i] = mx;
curr[i] = curr[i - vec[ind].r];
curr[i][ind]++;
res = max(res, dp[i]);
}
}
cout << res;
}
int main() {
FAST_IO;
//freopen("248.in", "r", stdin);
//freopen("248.out", "w", stdout);
//TEST_CASES;
solve(); cout << endl;
/*int a; cin >> a;
for (int i = 1; i <= a; i++){
cout << "Case #" << i << ": ";
solve();
}*/
}
# | 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... |