fork download
  1. #include<cstdio>
  2. #include<vector>
  3. #include<map>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. multimap<int, int> M;
  9. int n, k, sum=0;
  10. scanf("%d %d", &n, &k);
  11. vector<int> arr(n);
  12. for(int i=0; i<n; i++)
  13. scanf("%d", &arr[i]);
  14.  
  15. for(int i=0; i<k; i++)
  16. M.insert({arr[i], 0});
  17.  
  18. for(int i=0; i+k<n; i++)
  19. {
  20. sum+=(M.begin()+k/2)->first;
  21. M.erase(M.find(arr[i]));
  22. }
  23.  
  24. printf("%d", sum);
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
10 3
3
4
5
6
7
8
9
10
11
12
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:19: error: no match for ‘operator+’ (operand types are ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ and ‘int’)
    sum+=(M.begin()+k/2)->first;
          ~~~~~~~~~^~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/6/vector:60,
                 from prog.cpp:2:
/usr/include/c++/6/bits/stl_iterator.h:341:5: note: candidate: template<class _Iterator> std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&)
     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
     ^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:341:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   mismatched types ‘const std::reverse_iterator<_Iterator>’ and ‘int’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/6/vector:60,
                 from prog.cpp:2:
/usr/include/c++/6/bits/stl_iterator.h:1200:5: note: candidate: template<class _Iterator> std::move_iterator<_IteratorL> std::operator+(typename std::move_iterator<_IteratorL>::difference_type, const std::move_iterator<_IteratorL>&)
     operator+(typename move_iterator<_Iterator>::difference_type __n,
     ^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:1200:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   mismatched types ‘const std::move_iterator<_IteratorL>’ and ‘int’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/vector:65:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/stl_bvector.h:297:3: note: candidate: std::_Bit_iterator std::operator+(std::ptrdiff_t, const std::_Bit_iterator&)
   operator+(ptrdiff_t __n, const _Bit_iterator& __x)
   ^~~~~~~~
/usr/include/c++/6/bits/stl_bvector.h:297:3: note:   no known conversion for argument 1 from ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ to ‘std::ptrdiff_t {aka long int}’
/usr/include/c++/6/bits/stl_bvector.h:387:3: note: candidate: std::_Bit_const_iterator std::operator+(std::ptrdiff_t, const std::_Bit_const_iterator&)
   operator+(ptrdiff_t __n, const _Bit_const_iterator& __x)
   ^~~~~~~~
/usr/include/c++/6/bits/stl_bvector.h:387:3: note:   no known conversion for argument 1 from ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ to ‘std::ptrdiff_t {aka long int}’
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:4944:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:4944:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:53:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.tcc:1147:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator+(const _CharT* __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.tcc:1147:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   mismatched types ‘const _CharT*’ and ‘std::_Rb_tree_iterator<std::pair<const int, int> >’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:53:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.tcc:1163:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.tcc:1163:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘int’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:4981:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:4981:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:4997:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:4997:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:5009:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5009:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:5015:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5015:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:5021:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5021:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:5033:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
     operator+(const _CharT* __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5033:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   mismatched types ‘const _CharT*’ and ‘std::_Rb_tree_iterator<std::pair<const int, int> >’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:5039:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(_CharT, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&)
     operator+(_CharT __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5039:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘int’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:5045:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _CharT*)
     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5045:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/bits/stl_map.h:63,
                 from /usr/include/c++/6/map:61,
                 from prog.cpp:3:
/usr/include/c++/6/bits/basic_string.h:5051:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, _CharT)
     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5051:5: note:   template argument deduction/substitution failed:
prog.cpp:20:22: note:   ‘std::multimap<int, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const int, int> >}’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    sum+=(M.begin()+k/2)->first;
                      ^
stdout
Standard output is empty