# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334014 | 2020-12-08T06:06:14 Z | ronnith | Pod starim krovovima (COCI20_psk) | C++14 | 1 ms | 364 KB |
#include <bits/stdc++.h> typedef long long ll; #define mk make_pair #define f first #define s second using namespace std; int main(){ int n; scanf("%d", &n); ll x; pair<ll, ll> z[n]; ll sm = 0; ll sum = 0; for(int i = 0;i < n;i ++){ scanf("%lld%lld", &x, &z[i].f); z[i].s = i; sm = sm + x; sum += z[i].f; } sort(z, z + n); ll cnt = 0; ll ans = 0; ll an[n]; for(int i = 0;i < n;i ++){ cnt += z[i].f; if(sum - cnt >= sm){ ans = i + 1; } else break; } printf("%lld\n", ans); for(int i = 0;i < n;i ++){ if(i < ans) an[z[i].s] = 0; else { int h = min(sm, z[i].f); an[z[i].s] = h; sm -= h; } } for(int i = 0;i < n;i ++){ printf("%lld ", an[i]); } puts(""); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |