Submission #378726

#TimeUsernameProblemLanguageResultExecution timeMemory
378726casperwangGift (IZhO18_nicegift)C++14
7 / 100
2050 ms8172 KiB
#include <bits/stdc++.h> #define pb emplace_back #define pii pair<int,int> #define ff first #define ss second #define All(x) x.begin(), x.end() using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } struct Node { int X; vector <int> I; Node(int x) { X = x; } }; const int MAXN = 1000000; int N, K; vector <pii> arr; vector <Node> ops; bool flag = true; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> N >> K; arr.resize(N); for (int i = 0; i < N; i++) { auto &[v, id] = arr[i]; cin >> v; id = i + 1; } while (flag) { sort(All(arr), [](const pii x, const pii y){ return x.ff > y.ff; }); if (!arr[0].ff) { break; } else if (!arr[K-1].ff) { flag = false; break; } int sum = 0, res = (K < N ? arr[K].ff : 0); for (int i = 0; i < N; i++) sum += arr[i].ff; if (arr[0].ff * K > sum) { flag = false; } int p = min(arr[K-1].ff, (sum - (res * K)) / K); ops.pb(Node(p)); for (int i = 0; i < K; i++) { arr[i].ff -= p; ops[ops.size()-1].I.pb(arr[i].ss); } if (ops.size() > N) { flag = false; break; } } if (flag) { cout << ops.size() << '\n'; for (Node now : ops) { cout << now.X; for (int i : now.I) cout << ' ' << i; cout << '\n'; } } else { cout << -1 << '\n'; } }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:32:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |   auto &[v, id] = arr[i];
      |         ^
nicegift.cpp:58:18: warning: comparison of integer expressions of different signedness: 'std::vector<Node>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |   if (ops.size() > N) {
      |       ~~~~~~~~~~~^~~
#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...