Submission #997048

# Submission time Handle Problem Language Result Execution time Memory
997048 2024-06-11T16:17:31 Z MilosMilutinovic Gift (IZhO18_nicegift) C++14
26 / 100
435 ms 110796 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long s = accumulate(a.begin(), a.end(), 0LL);
  if (s % k != 0 || a[0] > s / k) {
    cout << -1 << '\n';
    return 0;
  }
  set<pair<long long, int>> st;
  for (int i = 0; i < n; i++) {
    st.emplace(a[i], i);
  }
  vector<vector<long long>> res;
  while (s > 0) {
    vector<int> ids;
    for (int foo = 0; foo < k; foo++) {
      auto it = prev(st.end());
      ids.push_back(it->second);
      st.erase(it);
    }
    long long v = a[ids.back()];
    if (!st.empty()) {
      v = min(v, s / k - prev(st.end())->first);
    }
    res.push_back({v});
    for (int i : ids) {
      res.back().push_back(i + 1);
    }
    for (int i : ids) {
      s -= v;
      a[i] -= v;
      if (a[i] > 0) {
        st.emplace(a[i], i);
      }
    }
  }
  cout << (int) res.size() << '\n';
  for (int i = 0; i < (int) res.size(); i++) {
    for (int j = 0; j < (int) res[i].size(); j++) {
      cout << res[i][j] << " ";
    }
    cout << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 0 ms 460 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 0 ms 460 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Runtime error 0 ms 348 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 0 ms 460 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Runtime error 0 ms 348 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 435 ms 110796 KB n=1000000
2 Correct 283 ms 64288 KB n=666666
3 Correct 152 ms 37968 KB n=400000
4 Correct 105 ms 26960 KB n=285714
5 Correct 6 ms 2140 KB n=20000
6 Correct 68 ms 17176 KB n=181818
7 Correct 3 ms 1372 KB n=10000
8 Correct 3 ms 856 KB n=6666
9 Correct 1 ms 604 KB n=4000
10 Correct 3 ms 604 KB n=2857
11 Correct 1 ms 604 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 0 ms 460 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Runtime error 0 ms 348 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -