답안 #1094217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094217 2024-09-29T03:15:55 Z Trisanu_Das Feast (NOI19_feast) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, k; cin >> n >> k;
  int a[n]; for(int i = 0; i < n; i++) cin >> a[i];
  int ans = 0, curr = 0, sm = 0;
  for(int i = 0; i < n; i++){
    if(a[i] >= 0) sm += a[i];
    curr += a[i];
    ans = max(ans, curr);
    curr = max(curr, 0);
  }
  if(k == 1) cout << ans << '\n';
  else cout << sm << '\n';
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:14:23: error: no matching function for call to 'max(long long int&, int)'
   14 |     curr = max(curr, 0);
      |                       ^
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 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:14:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   14 |     curr = max(curr, 0);
      |                       ^
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 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:14:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   14 |     curr = max(curr, 0);
      |                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from feast.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:
feast.cpp:14:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   14 |     curr = max(curr, 0);
      |                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from feast.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:
feast.cpp:14:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   14 |     curr = max(curr, 0);
      |                       ^