답안 #638250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638250 2022-09-05T06:19:06 Z iee Pod starim krovovima (COCI20_psk) C++17
40 / 50
1 ms 212 KB
// iee
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>

#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);

template <class T> void read(T &x) {
  x = 0; int f = 1, ch = getchar();
  while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
  while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
  x *= f;
}

int main() {
  int TT = 1; // cin >> TT;
  rep(CAS, 1, TT)
    work(CAS);
  return 0;
}
const int N = 1005;
int n, ans[N], sum, cnt;
pair<int, int> a[N];
void work(int CASE) {
  cin >> n;
  rep(i, 1, n) {
    int x;
    cin >> x;
    sum += x;
    cin >> a[i].fi;
    a[i].se = i;
  }
  sort(a + 1, a + n + 1, greater<pair<int, int>>());
  rep(i, 1, n)
    if (sum > 0) ans[a[i].se] = min(sum, a[i].fi), sum -= min(sum, a[i].fi);
    else ++cnt;
  cout << cnt << '\n';
  rep(i, 1, n) cout << ans[i] << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Incorrect 1 ms 212 KB Output isn't correct