제출 #893258

#제출 시각아이디문제언어결과실행 시간메모리
893258vjudge1Gift (IZhO18_nicegift)C++17
49 / 100
585 ms524288 KiB
// 以上帝的名义 // 候选硕士 #include <bits/stdc++.h> #ifdef local #include "algo/debug.h" #else #define dbg(x...) 0 #endif using namespace std ; using ll = long long ; #define int ll int32_t main() { cin.tie(0)->sync_with_stdio(false) ; ll n , k ; cin >> n >> k ; vector<ll> a(n) ; for (ll &i : a) cin >> i ; priority_queue<pair<ll,ll>> q ; for (int i = 0 ; i < n ; i++) { q.push({a[i], i}) ; } ll sum = 0 ; for (ll i : a) sum += i ; if (sum % k) { cout << -1 ; return 0 ; } if (sum / k < q.top().first) { cout << -1 ; return 0 ; } vector<deque<ll>> res ; while (q.size() >= k) { deque<ll> cur ; ll mn = INT_MAX ; for (int i = 0 ; i < k ; i++) { auto [value, ind] = q.top() ; q.pop() ; cur.push_back(ind) ; mn = value ; } if (q.size()) mn = min(mn * 1ll, (sum / k) - q.top().first) ; // assert(mn >= 0) ; sum -= k * mn ; for (ll& i : cur) { a[i] -= mn ; if (a[i]> 0) { q.push({a[i], i}) ; } } cur.push_front(mn) ; res.push_back(cur) ; } if (sum) { cout << -1 ; return 0 ; } reverse(res.begin(), res.end()) ; cout << (ll)res.size() << "\n" ; if (res.size()) { for (auto i : res) { cout << i.front() << ' ' ; i.pop_front() ; for (ll j : i) cout << j + 1 << ' ' ; cout << "\n" ; } } return 0 ; } // 希望白银

컴파일 시 표준 에러 (stderr) 메시지

nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:36:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   36 |     while (q.size() >= k) {
      |            ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...