Submission #1097922

#TimeUsernameProblemLanguageResultExecution timeMemory
1097922EkinOnalKnapsack (NOI18_knapsack)C++17
100 / 100
80 ms37068 KiB
//#pragma GCC optimize("O3,unroll-loops,Ofast") //#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define MAX 100005 #define pb push_back #define mp make_pair #define int long long #define f first #define s second #define vi vector<int> #define pii pair<int,int> #define si set<int> #define vpii vector<pair<int,int>> const int mod = 1e9+7; const int INF = 1e18; // myMap.begin()->first : key // myMap.begin()->second : value int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;b>>=1;ans%=mod;a%=mod;}return ans%mod;} int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;} int mul(long long a,long long b){return ((a%mod)*(b%mod))%mod;} int sum(long long a,long long b){return ((a%mod)+(b%mod))%mod;} typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_multiset; void solve(){ int S,n; cin>>S>>n; map<int,vpii> mpp; for(int i=1;i<=n;i++){ int a,b,c; cin>>a>>b>>c; mpp[b].pb({a,c}); } int cesid=1; int dp[S+5][S+5]{}; for(auto u : mpp){ sort(u.s.begin(),u.s.end(),greater<pii>()); for(int s=1;s<=S;s++){ dp[cesid][s]=dp[cesid-1][s]; int gelir=0,curr=0,now=1,gider=1; while(curr<u.s.size() && gider*u.f<=s){ gelir+=u.s[curr].f; dp[cesid][s]=max(dp[cesid][s],dp[cesid-1][s-gider*u.f]+gelir); now++; gider++; if(now>u.s[curr].s) now=1,curr++; } } cesid++; } int mx=0; for(int i=1;i<=S;i++) mx=max(mx,dp[cesid-1][i]); cout<<mx<<endl; return; } int32_t main(/*int32_t argc, char* argv[]*/){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("censor.in", "r", stdin); // freopen("censor.out", "w", stdout); int t=1; // cin >> t; while (t--) solve(); return 0; } /* int cesid=1; int dp[S+5][S+5]{}; for(auto u : mpp){ sort(u.s.begin(),u.s.end(),greater<pii>()); for(int s=1;s<=S;s++){ dp[cesid][s]=dp[cesid-1][s]; int gelir=0,curr=0; while(curr<u.s.size() && (curr+1)*u.f<=s){ gelir+=u.s[curr].f; int gider=(curr+1)*u.f; dp[cesid][s]=max(dp[cesid][s],dp[cesid-1][s-gider]+gelir); curr++; } } cesid++; } int mx=0; for(int i=1;i<=S;i++) mx=max(mx,dp[cesid-1][i]); cout<<mx<<endl; */

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:49:14: 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]
   49 |    while(curr<u.s.size() && gider*u.f<=s){
      |          ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...