#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<ll> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
vector<pair<ll, int>> sortedA;
for (int i = 0; i < N; i++) sortedA.emplace_back(A[i], i + 1);
sort(sortedA.begin(), sortedA.end());
vector<vector<int>> operations;
ll totalOps = 0;
while (!sortedA.empty()) {
vector<int> indices;
ll minVal = sortedA[0].first;
for (int i = 0; i < min(K, (int)sortedA.size()); i++) {
indices.push_back(sortedA[i].second);
sortedA[i].first -= minVal;
}
operations.push_back({minVal});
operations.back().insert(operations.back().end(), indices.begin(), indices.end());
totalOps += minVal;
sortedA.erase(remove_if(sortedA.begin(), sortedA.end(), [](pair<ll, int> p) { return p.first == 0; }), sortedA.end());
}
if ((ll)operations.size() * K > 3000000) {
cout << "-1\n";
return 0;
}
cout << operations.size() << "\n";
for (auto &op : operations) {
for (int x : op) cout << x << " ";
cout << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
nicegift.cpp: In function 'int main()':
nicegift.cpp:30:31: warning: narrowing conversion of 'minVal' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
30 | operations.push_back({minVal});
| ^~~~~~
nicegift.cpp:30:31: warning: narrowing conversion of 'minVal' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |