이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define maxn 2010
#define int long long
#define taskname "spainting"
using namespace std;
int s,n;
int dp[maxn][maxn];
vector <pair<int,int>> a[maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
// freopen(taskname".in","r",stdin);
// freopen(taskname".out","w",stdout);
cin>>s>>n;
for (int i=1; i<=n; i++)
{
int v,w,k; cin>>v>>w>>k;
if (w<=s&&k>0) a[w].push_back({v,k});
}
for (int i=0; i<=s; i++) for (int j=0; j<=s; j++) dp[i][j]=-1e18;
dp[0][0]=0;
for (int i=1; i<=s; i++)
{
sort(a[i].begin(),a[i].end(),greater<pair<int,int>>());
for (int j=0; j<=s; j++)
{
dp[i][j]=dp[i-1][j];
if (a[i].empty()) continue;
int cnt=0;
int used=0;
int it=0;
int sum=0;
while ((cnt+1)*i<=j&&it<(int)(a[i].size()))
{
cnt++;
sum+=a[i][it].first;
if (dp[i-1][j-cnt*i]!=-1e18)
dp[i][j]=max(dp[i][j],dp[i-1][j-cnt*i]+sum);
used++;
if (used==a[i][it].second)
{
used=0;
it++;
}
}
}
}
int ans=-1e18;
for (int i=0; i<=s; i++) for (int j=0; j<=s; j++) ans=max(ans,dp[i][j]);
cout<<ans;
}
# | 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... |