Submission #916634

#TimeUsernameProblemLanguageResultExecution timeMemory
916634AmrKnapsack (NOI18_knapsack)C++14
100 / 100
70 ms14424 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define S second #define F first #define all(x) (x).begin(),(x).end() #define sz size() #define Yes cout << "YES" << endl #define No cout << "NO" << endl #define pb(x) push_back(x); #define endl '\n' #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int N=3e5+7; ll INF=INT_MAX,mod=1e9+7; int TT=1; ll power(ll x, unsigned int y) { ll res = 1; x = x; // % mod; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) ; // % mod; y = y>>1; x = (x*x) ; // % mod; } return res; } ll dp[N]; vector<pair<ll,ll> > b[N]; void solve() { memset(dp,-1,sizeof dp); ll n , s; cin >> n >> s; swap(n,s); for(int i = 1; i <= n; i++) { ll price , w , k ;cin >> price >> w >> k; b[w].push_back({price,k}); } for(int i = 1; i <= s; i++) if(b[i].sz)sort(all(b[i]),greater<pair<ll,ll> > ()); dp[0] = 0; for(int i = 1; i<= s; i++) { if(b[i].sz==0) continue; for(int j = s; j>= 0; j--) { ll c = 1; ll cursum = 0; ll alllst = 0; ll l= 0; while(j-i*c>=0&&l<b[i].sz) { cursum+=b[i][l].F; if(dp[j-i*c] !=-1) dp[j] = max(dp[j],dp[j-i*c]+cursum); if(alllst+b[i][l].S==c) alllst+=b[i][l].S,l++; c++; } } } ll mx = 0; for(int i = 1; i<=s; i++) mx = max(mx,dp[i]); cout << mx << endl; } int main(){ //freopen("friday.in","r",stdin); //freopen("friday.out","w",stdout); fast; while(TT--) solve(); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:53:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             while(j-i*c>=0&&l<b[i].sz)
      |                              ^
#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...