Submission #844426

# Submission time Handle Problem Language Result Execution time Memory
844426 2023-09-05T13:09:05 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 348 KB
// author: erray
#include <bits/stdc++.h>

#ifdef DEBUG
  #include "debug.h"
#else
  #define debug(...) void(37)
#endif

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> T(N), Z(N);
  long long tot = 0;
  for (int i = 0; i < N; ++i) {
    cin >> T[i] >> Z[i];
    tot += T[i];
  }
  vector<int> ord(N);
  iota(ord.begin(), ord.end(), 0);  
  sort(ord.begin(), ord.end(), [&](int x, int y) {
    return Z[x] > Z[y];
  });
  int ans = 0;
  for (auto i : ord) {
    T[i] = min(0LL + Z[i], tot);
    tot -= T[i];
    ans += (T[i] == 0);
  }
  cout << ans << '\n';
  for (int i = 0; i < N; ++i) {
    cout << T[i] << " \n"[i == N - 1];
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct