# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199503 | 2020-02-01T17:02:22 Z | SamAnd | Pod starim krovovima (COCI20_psk) | C++17 | 6 ms | 376 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1003; struct ban { int i; int a, b; }; bool operator<(const ban& a, const ban& b) { return a.b < b.b; } int n; ban a[N]; int yans[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { a[i].i = i; scanf("%d%d", &a[i].a, &a[i].b); } sort(a + 1, a + n + 1); long long q = 0; for (int i = 1; i <= n; ++i) { q += a[i].a; a[i].a = 0; } for (int i = n; i >= 1; --i) { if (q > a[i].b) { q -= a[i].b; a[i].a = a[i].b; } else { a[i].a = q; q = 0; } } for (int i = 1; i <= n; ++i) yans[a[i].i] = a[i].a; int ans = 0; for (int i = 1; i <= n; ++i) { if (yans[i] == 0) ++ans; } printf("%d\n", ans); for (int i = 1; i <= n; ++i) printf("%d ", yans[i]); printf("\n"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 248 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 6 ms | 376 KB | Output is correct |