Submission #80730

#TimeUsernameProblemLanguageResultExecution timeMemory
80730inomGift (IZhO18_nicegift)C++14
18 / 100
2068 ms171152 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; #define ll long long #define mp make_pair const int MAXN = 1e6; pair <int, int> a[MAXN]; vector< vector< ll > > ans; int main() { int n, k; scanf("%d%d", &n, &k); set < pair <ll, int> > S; for (int i = 0; i < n; i++) { scanf("%d", &a[i].first); a[i].second = i + 1; S.insert(mp(-a[i].first, i + 1)); } vector <ll> res; res.resize(3); while (!S.empty()) { if (S.size() == 1) { printf("-1"); return 0; } res[0] = 1; pair <ll, int> P = *S.begin(); S.erase(S.begin()); res[1] = P.second; pair <ll, int> P2 = *S.begin(); S.erase(S.begin()); res[2] = P2.second; if (P.first != -1ll) { S.insert(mp(P.first + 1, P.second)); } if (P2.first != -1ll) { S.insert(mp(P2.first + 1, P2.second)); } ans.push_back(res); } if (!S.empty()) { printf("-1"); return 0; } printf("%d\n", (int)ans.size()); for (int i = 0; i < ans.size(); i++) { for (int j = 0; j <= k; j++) { printf("%lld ", ans[i][j]); } printf("\n"); } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++) {
                  ~~^~~~~~~~~~~~
nicegift.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i].first);
   ~~~~~^~~~~~~~~~~~~~~~~~~
#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...