이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=1e5+11;
int s, n, sz[N], dp[2011][32931];
struct gg
{
int v, w, sl;
}a[N];
bool cmp(gg x, gg y)
{
return x.v>y.v;
}
vector<pii> v;
void sol()
{
cin >> s >> n;
for(int i=1;i<=n;i++) cin >> a[i].v >> a[i].w >> a[i].sl;
sort(a+1, a+n+1, cmp);
v.push_back({0, 0});
for(int i=1;i<=s;i++) sz[i]=s/i;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=a[i].sl;j++)
{
if(sz[a[i].w])
{
v.push_back({a[i].v, a[i].w});
sz[a[i].w]--;
}
else break;
}
}
n=v.size();
for(int i=1;i<=n;i++) for(int j=0;j<=s;j++) dp[j][i]=-1e9;
dp[0][0]=0;
// for(auto x:v) cout << x.fi << ' ' << x.sc << el;
for(int i=1;i<=n;i++)
{
for(int j=v[i].sc;j<=s;j++)
{
dp[j][i]=max(dp[j][i], dp[j-v[i].sc][i-1]+v[i].fi);
}
for(int j=0;j<=s;j++) dp[j][i]=max(dp[j][i], dp[j][i-1]);
}
int ans=0;
for(int i=1;i<=n;i++) for(int j=0;j<=s;j++) ans=max(ans, dp[j][i]);
cout << ans;
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
# | 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... |