Submission #338537

# Submission time Handle Problem Language Result Execution time Memory
338537 2020-12-23T10:37:11 Z boykut Gift (IZhO18_nicegift) C++14
7 / 100
321 ms 30800 KB
#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});
   }
   if (k != 2) return 0;
   vector<tuple<int,int,int>> res;
   while (!q.empty()) {
      if (q.size() >= 2) {
         auto a = q.top(); q.pop();
         auto b = q.top(); q.pop();
         res.push_back(make_tuple(b.first, a.second, b.second));
         if (a.first > b.first)
            q.push({a.first-b.first, a.second});
      } else if (q.size() == 1) {
         return cout << "-1\n", 0;
      }
   }
   cout << res.size() << '\n';
   for (int i = 0; i < res.size(); i++) {
      cout << get<0>(res[i]) << ' ' << get<1>(res[i]) << ' ' << get<2>(res[i]) << '\n';
   }
   
   return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |    for (int i = 0; i < res.size(); i++) {
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 321 ms 30800 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -