Submission #990359

#TimeUsernameProblemLanguageResultExecution timeMemory
990359_rain_Knapsack (NOI18_knapsack)C++14
73 / 100
88 ms4188 KiB
/** author : Knquin_ **/ #include<bits/stdc++.h> using namespace std; using i64 = long long; using ui64 = unsigned long long; #define MASK(x) ((i64)(1) << (x)) #define BIT(mask , x) (((mask) >> (x)) & (1)) #define sz(x) (x).size() #define all(x) (x).begin() , (x).end() mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template<class T> bool maximize(T &a , T b) {if (a < b) return a = b , true; else return false;} template<class T> bool minimize(T &a , T b) {if (a > b) return a = b , true; else return false;} template<class T> T gcd(T x , T y) {while (y) swap(y , x %= y); return x;} template<class T> T lcm(T x , T y) {return (x * y) / gcd(x , y);} template <class T> void compress(vector<T> &a) { sort(a.begin() , a.end()); a.resize(unique(a.begin() , a.end()) - a.begin()); return; } template<class T> void printArr(T& container , string separator = "" , string finish = "\n") { for (auto& item : container) cout << item << separator; cout << finish; } const int maxn = 2e5; const int maxww = 2e3; int maxw , n; int v[maxn + 2] , w[maxn + 2] , k[maxn + 2]; namespace subtask1 { bool condition( ) { return n <= 100; } i64 dp[102][maxww + 2]; void cook(void) { i64 answer = 0; for (int i = 1; i <= n; ++i) { for (int turn = 0; turn <= min(k[i] , maxw / w[i]); ++turn) { for (int used = 0; used <= maxw - w[i] * turn; ++used) maximize(dp[i][used + w[i] * turn] , dp[i - 1][used] + (i64)v[i] * turn); } } for (int i = 0; i <= maxw; ++i) maximize(answer , dp[n][i]); cout << answer << '\n'; } } auto main(void)->int32_t { cin.tie(nullptr)->sync_with_stdio(false); const string name = "main"; if (fopen((name + ".inp").c_str() , "r")) { (void)!freopen((name + ".inp").c_str() , "r" , stdin); (void)!freopen((name + ".out").c_str() , "w+", stdout); } cin >> maxw >> n; for (int i = 1; i <= n; ++i) cin >> v[i] >> w[i] >> k[i]; if (subtask1::condition()) { subtask1::cook(); return 0; } }
#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...