Submission #844237

# Submission time Handle Problem Language Result Execution time Memory
844237 2023-09-05T11:42:46 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 368 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int64_t total = 0;
  vector<int64_t> T(N), Z(N);
  for (int i = 0;i < N; ++i) {
    cin >> T[i] >> Z[i];
    total += T[i];  
  }
  vector<int> idx(N);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&](int i, int j) { return Z[i] > Z[j]; });
  vector<int64_t> ans(N);
  for (int i = 0;i < N; ++i) {
    int j = idx[i];
    ans[j] = min(total, Z[j]);
    if (total < Z[j]) {
      break;
    } 
    total -= Z[j];
  }
  cout << count(ans.begin(), ans.end(), 0) << endl;
  for (int i = 0;i < N; ++i) {
    cout << ans[i] << ' ';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 368 KB Output is correct