Submission #976107

# Submission time Handle Problem Language Result Execution time Memory
976107 2024-05-06T07:49:02 Z vjudge1 Knapsack (NOI18_knapsack) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define pb push_back
#define endl '\n'
using namespace std;

int S,N,V,W,K,dp[2002];

void solve() {
	cin >> S >> N;
	dp[0] = 0;
	for (int i = 1; i <= S; i++) dp[i] = -1e9;
	for (int i = 1; i <= N; i++) {
		cin >> V >> W >> K;
		K = min(K, 2000);
		while (K--) {
			for (int j = S; j >= W; j--) {
				dp[j] = max(dp[j], dp[j - W] + V); 
			}
		}
	} cout << dp[S] << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int tttt = 1;
	//cin >> tttt;
	while (tttt--) solve();
}

Compilation message

knapsack.cpp: In function 'void solve()':
knapsack.cpp:17:18: error: no matching function for call to 'min(long long int&, int)'
   17 |   K = min(K, 2000);
      |                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
knapsack.cpp:17:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |   K = min(K, 2000);
      |                  ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
knapsack.cpp:17:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |   K = min(K, 2000);
      |                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
knapsack.cpp:17:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |   K = min(K, 2000);
      |                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
knapsack.cpp:17:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |   K = min(K, 2000);
      |                  ^