답안 #172896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172896 2020-01-02T17:46:58 Z elitewantsyou Gift (IZhO18_nicegift) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("Ofast")

#define fi first
#define se second

const int N = 1000010;

using namespace std;

int n;
int k;
long long a[N];

int main()
{
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        cin >> n >> k;
        set < pair < long long, int > > s;
        long long S = 0;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                s.insert({a[i], i});

                S += a[i];
        }
        if(1ll * (--s.end())->fi > S / k || S % k){
                cout << -1 << "\n";
                return 0;
        }

        vector < long long > qu;
        vector < vector < int > > res;
        vector < int > v;
        while(s.size() > 0){
                v.clear();
                for(int i = 0; i < k; i++){
                        v.push_back((--s.end())->se);
                        s.erase(--s.end());
                }
                long long rem = 0;
                if(!s.empty()){
                        rem = (--s.end())->fi;
                }

                long long l = 1, r = min(a[v.back()], S / k);
                long long  dif = a[v[0]] - rem;
                if(rem <= (S - dif * k) / k){
                        l = (S - rem * k) / k - 2;
                        r = min(r, l + 2);
                        l = max(l, 1);
                } else assert(0);
                while(l < r){
                        long long m = (l + r) / 2 + 1;
                        if(max(rem, a[v[0]] - m) > (S - m * k) / k){
                                r = m - 1;
                        } else{
                                l = m;
                        }
                }

                S -= k * l;
                res.push_back(v);
                qu.push_back(l);
                for(int i: v){
                        a[i] -= l;
                        if(!a[i]){
                                continue;
                        }
                        s.insert({a[i], i});
                }
        }
        cout << qu.size() << "\n";
        for(int i = 0; i < qu.size(); i++){
                cout << qu[i];
                for(int x: res[i]){
                        cout << " " << x;
                }
                cout << "\n";
        }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:56:37: error: no matching function for call to 'max(long long int&, int)'
                         l = max(l, 1);
                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 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:56:37: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
                         l = max(l, 1);
                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 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:56:37: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
                         l = max(l, 1);
                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 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:56:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
                         l = max(l, 1);
                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 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:56:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
                         l = max(l, 1);
                                     ^
nicegift.cpp:79:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < qu.size(); i++){
                        ~~^~~~~~~~~~~
nicegift.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("input.txt", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("output.txt", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~