Language: C++

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, s; cin >> n >> s;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  V<lint> c(n + 1); for (int i = 0; i < n; ++i) c[i + 1] = c[i] + a[i];
  int res = 1e9;
  for (int i = 0; i < n; ++i) {
    auto itr = lower_bound(begin(c), end(c), s + c[i]);
    if (itr != end(c)) res = min(res, distance(next(begin(c), i), itr));
  }
  cout << (res != 1e9 ? res : 0) << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:33: error: no matching function for call to 'min(int&, std::__iterator_traits<__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int, std::allocator<long long int> > >, void>::difference_type)'
   18 |     if (itr != end(c)) res = min(res, distance(next(begin(c), i), itr));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:18:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__iterator_traits<__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int, std::allocator<long long int> > >, void>::difference_type' {aka 'long int'})
   18 |     if (itr != end(c)) res = min(res, distance(next(begin(c), i), itr));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:18:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   18 |     if (itr != end(c)) res = min(res, distance(next(begin(c), i), itr));
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~