Submission #90654

#TimeUsernameProblemLanguageResultExecution timeMemory
90654adletGift (IZhO18_nicegift)C++17
7 / 100
2069 ms3784 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) using namespace std; typedef long long ll; const int N = 2e5 + 5; const int mod = 1e9 + 7; const double PI = acos(-1.0); struct item { int x, i, j; }; vector < item > ans; pair < int, int > a[N]; int n, k, mx; ll sum; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i].first; sum += a[i].first; mx = max(mx, a[i].first); a[i].second = i; } sort(a + 1, a + n + 1); if (sum % k != 0 || mx > sum / k) { cout << -1; return 0; } while (sum) for (int i = 1; i <= n; ++i) { if (!a[i].first) continue; for (int j = n; j > i; --j) { if (!a[i].first) break; if (!a[j].first) continue; ans.push_back({1, a[i].second, a[j].second}); --a[i].first; --a[j].first; sum -= 2; } } cout << ans.size() << "\n"; for (auto it : ans) { cout << it.x << " " << it.i << " " << it.j << "\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...