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>
#define int long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define gcd __gcd
using namespace std;
int n,m,s,k,i,j,ans,dp[200005],a[200005],b[200005],c[200005],cnt[200005];
vector<pii> v[200005],nivtebi;
signed main() {
cin>>s>>n;
for(i=1; i<=n; i++){
cin>>a[i]>>b[i]>>c[i];
cnt[b[i]]+=c[i];
v[b[i]].pb({a[i],c[i]});
}
nivtebi.pb({0, 0});
for(k=1; k<=s; k++){
sort(v[k].rbegin(),v[k].rend());
int raod=min(s/k,cnt[k]);
for(i=0; i<v[k].size(); i++){
if(v[k][i].ss<=raod) {
for (int j=1; j<=v[k][i].ss; j++) {
nivtebi.pb({k, v[k][i].ff});
}
raod-=v[k][i].ss;
} else {
for (int j=1; j<=raod; j++) {
nivtebi.pb({k, v[k][i].ff});
}
raod=0;
break;
}
}
}
for(k=1; k<nivtebi.size(); k++){
for(i=s; i>=0; i--){
if (i>=nivtebi[k].ff)
dp[i]=max(dp[i-nivtebi[k].ff]+nivtebi[k].ss,dp[i]);
ans=max(ans, dp[i]);
}
}
cout<<ans;
}
Compilation message (stderr)
knapsack.cpp: In function 'int main()':
knapsack.cpp:23:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(i=0; i<v[k].size(); i++){
| ~^~~~~~~~~~~~
knapsack.cpp:38:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(k=1; k<nivtebi.size(); k++){
| ~^~~~~~~~~~~~~~~
# | 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... |