Submission #1081270

#TimeUsernameProblemLanguageResultExecution timeMemory
1081270DeathIsAweGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int leftside[200001], rightside[200001];


int32_t main() {
    int n; cin >> n;
    vector<int> arr(n);
    for (int i=0;i<n;i++) {
        cin >> arr[i];
    }
    

    leftside[0] = 0;
    for (int i=1;i<n;i++) {
        leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, 0);
    }
    rightside[n-1] = 0;
    for (int i=n-2;i>-1;i--) {
        rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, 0);
    }


    int ans = INT_MAX, curans;
    if (leftside[n-1] > rightside[0]) {
        ans = rightside[0];
    } else {
        ans = leftside[n-1];
    }
    for (int i=1;i<n-1;i++) {
        curans = leftside[i-1] + rightside[i+1];
        if (arr[i+1] - arr[i] - leftside[i-1] > arr[i-1] - arr[i] - rightside[i+1]) {
            curans += max(arr[i+1] - arr[i] - leftside[i-1] + 1, 0);
        } else {
            curans += max(arr[i-1] - arr[i] - rightside[i+1] + 1, 0);
        }
        if (curans < ans) {
            ans = curans;
        }
    }
    cout << ans;
}

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:17:67: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   17 |         leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, 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 Main.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:
Main.cpp:17:67: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |         leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, 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 Main.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:
Main.cpp:17:67: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |         leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, 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 Main.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:
Main.cpp:17:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |         leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, 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 Main.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:
Main.cpp:17:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |         leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, 0);
      |                                                                   ^
Main.cpp:21:69: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   21 |         rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, 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 Main.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:
Main.cpp:21:69: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   21 |         rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, 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 Main.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:
Main.cpp:21:69: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   21 |         rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, 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 Main.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:
Main.cpp:21:69: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   21 |         rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, 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 Main.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:
Main.cpp:21:69: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   21 |         rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, 0);
      |                                                                     ^
Main.cpp:34:67: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   34 |             curans += max(arr[i+1] - arr[i] - leftside[i-1] + 1, 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 Main.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:
Main.cpp:34:67: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |             curans += max(arr[i+1] - arr[i] - leftside[i-1] + 1, 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 Main.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:
Main.cpp:34:67: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |             curans += max(arr[i+1] - arr[i] - leftside[i-1] + 1, 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 Main.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:
Main.cpp:34:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |             curans += max(arr[i+1] - arr[i] - leftside[i-1] + 1, 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 Main.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:
Main.cpp:34:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   34 |             curans += max(arr[i+1] - arr[i] - leftside[i-1] + 1, 0);
      |                                                                   ^
Main.cpp:36:68: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   36 |             curans += max(arr[i-1] - arr[i] - rightside[i+1] + 1, 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 Main.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:
Main.cpp:36:68: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   36 |             curans += max(arr[i-1] - arr[i] - rightside[i+1] + 1, 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 Main.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:
Main.cpp:36:68: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   36 |             curans += max(arr[i-1] - arr[i] - rightside[i+1] + 1, 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 Main.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:
Main.cpp:36:68: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |             curans += max(arr[i-1] - arr[i] - rightside[i+1] + 1, 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 Main.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:
Main.cpp:36:68: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |             curans += max(arr[i-1] - arr[i] - rightside[i+1] + 1, 0);
      |                                                                    ^