This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll s,n;
cin >> s >> n;
vector<vector<pair<ll,ll>>> v(s+1);
for(int i=0; i<n; i++){
ll val,w,k;
cin >> val >> w >> k;
v[w].push_back({val,k});
}
for(int i=1; i<=s; i++){
sort(begin(v[i]),end(v[i]),greater<pair<ll,ll>>());
}
vector<vector<ll>> dp(s+1,vector<ll> (s+1,0));
for(int i=1; i<=s; i++){
for(int j=1; j<=s; j++){
dp[i][j] = max(dp[i][j],dp[i-1][j]);
ll t = 1, cont = 0;
for(int x=0; x<(int)v[i].size(); x++){
ll f = 1;
while(f <= v[i][x].second){
if(j - t*i < 0) goto fin;
dp[i][j] = max(dp[i][j],dp[i-1][j - t*i] + f*v[i][x].first + cont);
t++; f++;
}
cont += (v[i][x].first*v[i][x].second);
}
fin:
continue;
}
}
cout << dp[s][s] << endl;
}
# | 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... |