제출 #1107584

#제출 시각아이디문제언어결과실행 시간메모리
1107584adkjtKnapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second vector<pair<long long,long long>> V[2222]; long long dp[2222]; pair<long long,pair<long long,long long>> a[111111];//v,w,k int main() { ios_base::sync_with_stdio(0); cin.tie(0); int s,n; cin>>s>>n; for(int i=1; i<=n; i++) { cin>>a[i].f>>a[i].s.f>>a[i].s.s; if(a[i].s.f>s) continue; V[a[i].s.f].push_back({-a[i].f,a[i].s.s}); } for(int i=1; i<=s; i++) dp[i]=-1; for(int i=1; i<=s; i++) sort(V[i].begin(),V[i].end()); for(int i=1; i<=s; i++) { if (V[i].empty()) continue; int j = 0; for(auto x:V[i])//v,k { re: for (int w = s; w - i >= 0; w--) { dp[w] = max(dp[w], dp[w - i] - x.f); } x.s--; if (x.s == 0) { continue; } else goto re; } } int ans=0; for(int i=1; i<=s; i++) ans=max(ans,dp[i]); cout<<ans; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:26:13: warning: unused variable 'j' [-Wunused-variable]
   26 |         int j = 0;
      |             ^
knapsack.cpp:47:26: error: no matching function for call to 'max(int&, long long int&)'
   47 |         ans=max(ans,dp[i]);
      |                          ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
knapsack.cpp:47:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   47 |         ans=max(ans,dp[i]);
      |                          ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
knapsack.cpp:47:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   47 |         ans=max(ans,dp[i]);
      |                          ^
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:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
knapsack.cpp:47:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |         ans=max(ans,dp[i]);
      |                          ^
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:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
knapsack.cpp:47:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |         ans=max(ans,dp[i]);
      |                          ^