이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define pll pair<long long, long long>
using namespace std;
void solve(){
ll s,n;
cin >> s >> n;
vector<pll> arr[s+5];
for(int i=1;i<=n;i++){
ll a,b,c;
cin >> a >> b >> c;
arr[b].pb({a,c});
}
vector<pll> v;
for(int i=1;i<=s;i++){
if(arr[i].size()==0) continue;
ll now = s/i;
sort(arr[i].begin(),arr[i].end(),greater<pll>());
ll sz = arr[i].size();
for(int j=0;j<sz;j++){
if(now==0) break;
while(arr[i][j].se>0&&now>0){
ll val = arr[i][j].fi;
v.pb({i,val});
arr[i][j].se--;
now--;
}
}
}
ll dp[s+5] = {0};
ll INF = -1;
for(int i=0;i<=s+1;i++){
dp[i] = INF;
}
dp[0] = 0;
for(auto i:v){
for(int j=s;j>=i.fi;j--){
dp[j] = max(dp[j],dp[j-1]);
if(dp[j-i.fi]==INF) continue;
dp[j] = max(dp[j],dp[j-i.fi]+i.se);
}
}
ll ans = 0;
for(int i=1;i<=s;i++){
ans = max(ans,dp[i]);
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tc = 1;
// cin >> tc;
while(tc--){
solve();
}
}
# | 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... |