이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |