Submission #503506

#TimeUsernameProblemLanguageResultExecution timeMemory
503506jparkFeast (NOI19_feast)C++14
Compilation error
0 ms0 KiB
#include<iostream> #define ll long long using namespace std; int main(){ int n,k; cin >> n >> k; int arr[n]; int pre[n+1]; int negc = 0; int a; bool ans = false; for(int x=0; x<n; x++){ cin >> a; arr[x] = a; pre[x] = 0; if(a<0) ++negc; } pre[n] = 0; ll total = 0; if(negc==0&&!ans){ for(int x=0; x<n; x++){ total += arr[x]; } cout << total; ans = true; } if(negc==1&&!ans){ if(k>=2){ for(int x=0; x<n; x++){ if(arr[x]>0){ total += arr[x]; } } cout << total; } else{ ll all = 0; for(int x=0; x<n; x++){ all += arr[x]; } ll before,after = 0; bool reached = false; for(int x=0; x<n; x++){ if(arr[x]<0){ reached = true; continue; } if(reached){ after += arr[x]; } else{ before += arr[x]; } } total = max(all,max(before,after)); } ans = true; } if(k==1&&!ans){ pre[0] = 0; for(int x=1; x<n+1; x++){ pre[x] = pre[x-1]+arr[x-1]; } int l,r = 0; while(r<n){ total = max(total,pre[r]-pre[l]); if(l==r){ ++r; continue; } } } }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:66:44: error: no matching function for call to 'max(long long int&, int)'
   66 |             total = max(total,pre[r]-pre[l]);
      |                                            ^
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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from feast.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:
feast.cpp:66:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   66 |             total = max(total,pre[r]-pre[l]);
      |                                            ^
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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from feast.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:
feast.cpp:66:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   66 |             total = max(total,pre[r]-pre[l]);
      |                                            ^