Submission #170898

# Submission time Handle Problem Language Result Execution time Memory
170898 2019-12-26T16:42:56 Z emil_physmath Gift (IZhO18_nicegift) C++17
Compilation error
0 ms 0 KB
#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, max(1, sum / k - it->first - 1));
        if (!mn) throw;
        // it->first <= (sum - k * mn) / k
        // k * it->first <= sum - k * mn
        // mn * k <= sum - k * it->first
        // mn <= sum / k - it->first
        /*
            mn = min(mn, a.rbegin()->first - it->first + 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

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:56: error: no matching function for call to 'max(int, llong)'
             mn = min(mn, max(1, sum / k - it->first - 1));
                                                        ^
In file included from /usr/include/c++/7/algorithm:61:0,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:56: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'llong {aka long long int}')
             mn = min(mn, max(1, sum / k - it->first - 1));
                                                        ^
In file included from /usr/include/c++/7/algorithm:61:0,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:56: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'llong {aka long long int}')
             mn = min(mn, max(1, sum / k - it->first - 1));
                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
             mn = min(mn, max(1, sum / k - it->first - 1));
                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
nicegift.cpp:47:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
             mn = min(mn, max(1, sum / k - it->first - 1));
                                                        ^