제출 #623785

#제출 시각아이디문제언어결과실행 시간메모리
623785BobonbushKnapsack (NOI18_knapsack)C++17
100 / 100
56 ms3876 KiB
#include <bits/stdc++.h> #define foreach for #define in : using namespace std; typedef long long ll; long long MODULO = 998244353; /* Konichiwa Konichiwa Ara ~~ ara Bob no taisuki - Shinobu Kocho * * * * * * * * * * * I love SHINOBU <3 <3 <3 * * * * * * * * * */ /* _________________________ Author : Bob15324 _________________________ */ /* okay i'm hoping that somebody pray for me I'm praying that somebody hope for me I'm staying where nobody 'posed to be p-p-posted being a wreak of emotions ready to go whenever just let me know the road is long so put the pedal into the floor the enemy's on my trail my energy unavailble Imma tell em hasta luego they wanna plot on my trot to the top I've been outta shape thinking out the box I'm an astronaut i balsted off the planet rock to cause catastrophe and it matters more because i had it not had i thought about wreaking havoc on an opposition kinda shocking they wanted static with precision i'm automatic quarterback i ain't talking sacking pack itpack it up i don't panic who the baddest it doesn't matter cause we at ya throat */ // EVERYBODY WANT TO BE MY ENEMY template<class X , class Y> bool Minimize(X & x , Y y) { if( x == -1|| (x >y && y >= 0 ) ) { x = y; return true; } return false; } template<class X , class Y> bool Maximize(X & x , Y y) { if( x < y) { x = y; return true; } return false; } template<class X , class Y> void Add(X &x , Y y ) { x += y; if(x >= MODULO) { x -= MODULO; } } template<class X , class Y> void Sub(X &x ,Y y) { x -= y; if(x < 0) { x += MODULO; } } /* End of templates. Let's see what do we have here */ const int N = 1e5+1; const int S = 2e3+1; int s , n ; int dp[S]; vector<pair<int ,int >>List_item[S] , List; void Prepare() { } void Input() { cin >> s >> n; for(int i = 1 ; i <= n ; i++) { int v , k; int w ; cin >> v; cin >> w >> k; List_item[w].push_back(make_pair(v , k)); } } void Process() { for(int i = 1; i <= s ; i++) { sort(List_item[i].begin() , List_item[i].end() , greater<pair<int,int >>()); int temp = i; foreach(pair<int ,int > items in List_item[i]) { for(int j = 1 ; j <= items.second ; j++ ) { if(temp > s)break; List.push_back(make_pair(items.first , i)); temp += i; } } } foreach(pair<int ,int > temp in List) { for(int j =s ; j >= temp.second ; j--) { dp[j] = max(dp[j] , dp[j- temp.second] + temp.first); } } cout << dp[s]; } int main() { ios_base :: sync_with_stdio(0);cin.tie(0); int test; test = 1; Prepare(); while(test--) { Input(); Process(); } return 0; } //Ehem. My code is amazing. Pay me 2$.Thank you.
#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...