Submission #975777

#TimeUsernameProblemLanguageResultExecution timeMemory
975777IsamKnapsack (NOI18_knapsack)C++17
73 / 100
195 ms262144 KiB
#include<bits/stdc++.h>
using namespace std;
 
#define eb emplace_back
#define int long long

constexpr int sz = 1e5 + 5;
constexpr int inf = (int)1E9;

int n, s;

struct ou{
	int v, w, k;
} a[sz];

int tot;
array<int, 2> b[sz * 1000];

int dp[2005];


signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> s >> n;
	for(register int i = 1; i <= n; ++i){
		cin >> a[i].v >> a[i].w >> a[i].k;
		a[i].k = min(a[i].k, 2000ll);
		
		for(register int j = 1; j <= a[i].k; ++j){
			b[++tot] = array<int, 2>{a[i].w, a[i].v};
		}
		
		
	}
	
	for(register int i = 1; i <= 2000; ++i){
		dp[i] = -inf;
	}
	
	for(register int i = 1; i <= tot; ++i){
		for(register int j = s; j >= b[i][0]; --j){
			dp[j] = max(dp[j], dp[j - b[i][0]] + b[i][1]);
		}
	}
	
	int ans = *max_element(dp, dp+s+1);
	
	cout << ans << '\n';
	
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:25:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   25 |  for(register int i = 1; i <= n; ++i){
      |                   ^
knapsack.cpp:29:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   29 |   for(register int j = 1; j <= a[i].k; ++j){
      |                    ^
knapsack.cpp:36:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |  for(register int i = 1; i <= 2000; ++i){
      |                   ^
knapsack.cpp:40:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |  for(register int i = 1; i <= tot; ++i){
      |                   ^
knapsack.cpp:41:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |   for(register int j = s; j >= b[i][0]; --j){
      |                    ^
#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...