# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
212042 | NONAME | Pod starim krovovima (COCI20_psk) | C++17 | 5 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <time.h>
#ifndef _LOCAL
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif
#define sz(x) int(x.size())
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define N 100500
#define oo ll(1e16)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define ft first
#define sd second
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
#define re return
#define nins 4294967295
using namespace std;
typedef long long ll;
typedef long double ld;
ll add(ll x, ll y, ll mod) {
return (mod == 0) ? (x + y) : (x + y) % mod;
}
ll mul(ll x, ll y, ll mod) {
return (mod == 0) ? (x * y) : (x * y) % ll(mod);
}
struct st {
ll x, y;
int ps;
st (ll x, ll y, ll ps) : x(x), y(y), ps(ps) {}
};
bool cmp(st x, st y) {
return x.y == y.y ? x.x < y.x : x.y < y.y;
}
vector <st> v;
int l, r, n, ans, rs[N];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _LOCAL
in("input.txt");
clock_t start_time = clock();
#endif
cin >> n;
for (int i = 0; i < n; i++) {
ll x, y; cin >> x >> y;
v.pb(st(x, y, i));
}
sort(v.begin(), v.end(), cmp);
l = n - 2; r = n - 1;
while (l >= 0) {
if (l == r) l--;
ll o = min(v[l].x, v[r].y - v[r].x);
v[l].x -= o;
v[r].x += o;
if (v[l].x == 0) l--;
if (v[r].x == v[r].y) r--;
}
for (int i = 0; i < n; i++)
rs[v[i].ps] = v[i].x;
for (int i = 0; i < n; i++)
ans += !rs[i];
cout << ans << el;
for (int i = 0; i < n; i++)
cout << rs[i] << ' ';
#ifdef _LOCAL
cerr.precision(4); cerr << fixed;
cerr << el;
cerr << "Time :: " << ld(clock() - start_time) / CLOCKS_PER_SEC << el;
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |