Submission #170887

#TimeUsernameProblemLanguageResultExecution timeMemory
170887emil_physmathGift (IZhO18_nicegift)C++17
Compilation error
0 ms0 KiB
#include <algorithm> #include <iostream> #include <vector> #include <queue> #include <cmath> #include <map> #include <set> using namespace std; typedef double ldouble; typedef long long llong; const int maxN = 100001; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; vector<llong> arr(n); multiset<pair<llong, int>> a; llong mx = -1, sum = 0; for (int i = 0; i < n; ++i) { cin >> arr[i]; sum += arr[i]; mx = max(mx, arr[i]); a.insert({arr[i], i}); } if (sum % k || mx > sum / k) { cout << -1 << endl; exit(0); } vector<pair<llong, vector<int>>> ans; while (a.rbegin()->first) { vector<int> cur; llong mn = a.rbegin()->first; auto it = a.rbegin(); for (; cur.size() < k; ++it) { cur.push_back(it->second); mn = min(mn, it->first); } if (it != a.rend()) mn = min(mn, a.rbegin()->first - *it + 1); /* if (!mn) { cout << -1 << endl; exit(0); } */ for (int x: cur) { a.erase({arr[x], x}); a.insert({arr[x] -= mn, x}); } ans.push_back({mn, cur}); /*cerr << "a` "; for (pair<llong, int> i: a) cerr << i.first << ' '; cerr << endl;*/ } cout << ans.size() << '\n'; for (auto x: ans) { cout << x.first << ' '; for (int y: x.second) cout << y + 1 << ' '; cout << '\n'; } } // 6 5 4 3 x // x x-1 x-2 x-3 x

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:41:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (; cur.size() < k; ++it)
                ~~~~~~~~~~~^~~
nicegift.cpp:47:44: error: no match for 'operator-' (operand types are 'const long long int' and 'const std::pair<long long int, int>')
             mn = min(mn, a.rbegin()->first - *it + 1);
                          ~~~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:389:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
     operator-(const reverse_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:389:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:47: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'const long long int'
             mn = min(mn, a.rbegin()->first - *it + 1);
                                               ^~
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:1191:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
     operator-(const move_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1191:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:47: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'const long long int'
             mn = min(mn, a.rbegin()->first - *it + 1);
                                               ^~
In file included from /usr/include/c++/7/vector:65:0,
                 from nicegift.cpp:3:
/usr/include/c++/7/bits/stl_bvector.h:208:3: note: candidate: std::ptrdiff_t std::operator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)
   operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
   ^~~~~~~~
/usr/include/c++/7/bits/stl_bvector.h:208:3: note:   no known conversion for argument 1 from 'const long long int' to 'const std::_Bit_iterator_base&'
In file included from /usr/include/c++/7/deque:64:0,
                 from /usr/include/c++/7/queue:60,
                 from nicegift.cpp:4:
/usr/include/c++/7/bits/stl_deque.h:351:5: note: candidate: template<class _Tp, class _Ref, class _Ptr> typename std::_Deque_iterator<_Tp, _Ref, _Ptr>::difference_type std::operator-(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _Ref, _Ptr>&)
     operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_deque.h:351:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:47: note:   mismatched types 'const std::_Deque_iterator<_Tp, _Ref, _Ptr>' and 'const long long int'
             mn = min(mn, a.rbegin()->first - *it + 1);
                                               ^~
In file included from /usr/include/c++/7/deque:64:0,
                 from /usr/include/c++/7/queue:60,
                 from nicegift.cpp:4:
/usr/include/c++/7/bits/stl_deque.h:363:5: note: candidate: template<class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> typename std::_Deque_iterator<_Tp, _Ref, _Ptr>::difference_type std::operator-(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _RefR, _PtrR>&)
     operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_deque.h:363:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:47: note:   mismatched types 'const std::_Deque_iterator<_Tp, _Ref, _Ptr>' and 'const long long int'
             mn = min(mn, a.rbegin()->first - *it + 1);
                                               ^~