Submission #330040

# Submission time Handle Problem Language Result Execution time Memory
330040 2020-11-23T14:03:56 Z oak Knapsack (NOI18_knapsack) C++14
100 / 100
97 ms 5100 KB
#include<bits/stdc++.h>
using namespace std;
vector<pair<long long,int> > wei[2001],vc;
long long dp[2001];
int main(){
	int n,s,i,j,w,k;
	long long v;
	scanf("%d %d",&s,&n);
	for(i=0;i<n;i++){
		scanf("%lld %d %d",&v,&w,&k);
		wei[w].push_back(make_pair(v,k));
	}
	for(i=1;i<=s;i++){
		sort(wei[i].begin(),wei[i].end(),greater<pair<long long,int> >());
		int remain = s/i;
		for(j = 0; j<wei[i].size() && remain >0; j++){
			int sel = min(remain,wei[i][j].second);
			remain -= sel;
			while(sel--)vc.push_back(make_pair(wei[i][j].first,i));
		}
	}
	for(i=0;i<vc.size();i++){
		for(j = s;j >= vc[i].second;j--){
			dp[j] = max(dp[j],dp[j-vc[i].second] + vc[i].first);
		}
	}
	printf("%lld",dp[s]);
}

Compilation message

knapsack.cpp: In function 'int main()':
knapsack.cpp:16:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for(j = 0; j<wei[i].size() && remain >0; j++){
      |              ~^~~~~~~~~~~~~~
knapsack.cpp:22:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(i=0;i<vc.size();i++){
      |          ~^~~~~~~~~~
knapsack.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |  scanf("%d %d",&s,&n);
      |  ~~~~~^~~~~~~~~~~~~~~
knapsack.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |   scanf("%lld %d %d",&v,&w,&k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 6 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 5 ms 492 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 4 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 5 ms 492 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 4 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 40 ms 3424 KB Output is correct
36 Correct 45 ms 3552 KB Output is correct
37 Correct 56 ms 3424 KB Output is correct
38 Correct 39 ms 3796 KB Output is correct
39 Correct 45 ms 4380 KB Output is correct
40 Correct 74 ms 5100 KB Output is correct
41 Correct 52 ms 4336 KB Output is correct
42 Correct 54 ms 4336 KB Output is correct
43 Correct 67 ms 4332 KB Output is correct
44 Correct 72 ms 4460 KB Output is correct
45 Correct 43 ms 4844 KB Output is correct
46 Correct 44 ms 4064 KB Output is correct
47 Correct 46 ms 5100 KB Output is correct
48 Correct 57 ms 4972 KB Output is correct
49 Correct 44 ms 4716 KB Output is correct
50 Correct 97 ms 4588 KB Output is correct