Submission #338540

#TimeUsernameProblemLanguageResultExecution timeMemory
338540boykutGift (IZhO18_nicegift)C++14
7 / 100
516 ms66856 KiB
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector <int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } priority_queue <pair <int, int>> q; for (int i = 0; i < n; i++) { q.push({a[i], 1+i}); } vector <vector <int>> res; while (!q.empty()) { if (q.size() >= k) { vector <pair <int, int> > vec; for (int i = 0; i < k; i++) { vec.push_back(q.top()); q.pop(); } res.push_back({vec.back().first}); for (int i = 0; i < k; i++) { res[res.size()-1].push_back(vec[i].second); vec[i].first -= vec.back().first; } for (int i = 0; i < k; i++) { if (vec[i].first > 0) q.push(vec[i]); } } else if (q.size() > 0 && q.size() < k) { return cout << "-1\n", 0; } } cout << res.size() << '\n'; for (int i = 0; i < res.size(); i++) { for (int j = 0; j < res[i].size(); j++) { cout << res[i][j] << ' '; } cout << '\n'; } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:20:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |       if (q.size() >= k) {
      |           ~~~~~~~~~^~~~
nicegift.cpp:34:43: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |       } else if (q.size() > 0 && q.size() < k) {
      |                                  ~~~~~~~~~^~~
nicegift.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for (int i = 0; i < res.size(); i++) {
      |                    ~~^~~~~~~~~~~~
nicegift.cpp:40:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |       for (int j = 0; j < res[i].size(); j++) {
      |                       ~~^~~~~~~~~~~~~~~
#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...