이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<char> VC;
typedef vector<vector<char>> VVC;
typedef vector<bool> VB;
typedef vector<vector<bool>> VVB;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<pair<int, int>> VPI;
typedef vector<pair<long long, long long>> VPL;
#define LINE '\n'
#define SPACE ' '
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
// static const ll MOD = 998244353;
ll binpow(ll a, ll b, ll mod)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
{
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
void solve()
{
int s, n;
cin >> s >> n;
vector<VPL> vec(s + 1);
FOR(i, 0, n)
{
ll v, w, k;
cin >> v >> w >> k;
vec[w].PB({v, k});
}
FOR(i, 0, n)
{
sort(RALL(vec[i]));
}
VL dp(s+1);
FOR(i, 1, s + 1) {
int ct = s / i;
for(auto [v, k] : vec[i]) {
while(ct > 0 && k > 0) {
for(int j = s; j-i >= 0; j--) {
dp[j] = max(dp[j], dp[j-i] + v);
}
ct--;
k--;
}
if(ct <= 0) break;
}
}
cout << *max_element(ALL(dp)) << LINE;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while (t--)
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... |