32252023-02-22 21:01:11zsomborVállalkozócpp17Forditási hiba
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, m, kesz = 0, ans = 0;
vector <int> o(1e4 + 1);
vector <int> v;

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> o[i];
    v.resize(m);
    for (int& i : v) cin >> i;
    sort(v.begin(), v.end());
    for (int i = 1; i <= n; i++) {
        kesz = max(kesz, lower_bound(v.begin(), v.end(), i) - v.begin());
        if (kesz + o[i] > m) { ans += m - kesz; break; }
        kesz += o[i];
        ans += o[i];
    }
    cout << ans;
}
Forditási hiba
exit status 1
main.cpp: In function 'int main()':
main.cpp:18:19: error: no matching function for call to 'max(int&, __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
   18 |         kesz = max(kesz, lower_bound(v.begin(), v.end(), i) - v.begin());
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from main.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
main.cpp:18:19: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<i...