이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2005;
const ll inf = -1e15;
int S, n;
void solve()
{
cin >> S >> n;
map<ll, vector<pair<ll, ll>>> weight;
for(int i=0; i<n; i++)
{
ll w, val, sl;
cin >> val >> w >> sl;
weight[w].push_back({val, sl});
}
int id = 1;
vector<vector<ll>> ans((int)weight.size()+1, vector<ll>(S+1, inf));
ans[0][0] = 0;
for(auto [w, items] : weight)
{
sort(items.begin(), items.end(), greater<pair<ll, ll>>());
for(int i=0; i<=S; i++)
{
ans[id][i] = ans[id-1][i];
ll sl = 0, profit = 0, type_at = 0, used = 0;
while((sl+1) * w <= i && type_at < (ll)items.size())
{
sl += 1;
profit += items[type_at].first;
if (ans[id-1][i-sl*w] != inf)
{
ans[id][i] = max(ans[id][i], ans[id-1][i-sl*w] + profit);
}
used++;
if (used == (ll)items[type_at].second)
{
used = 0;
type_at++;
}
}
}
id++;
}
cout << *max_element(ans.back().begin(), ans.back().end());
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
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... |