# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
732247 | vjudge1 | Pod starim krovovima (COCI20_psk) | C++17 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author: MisterReaper (Ahmet Alp Orakci)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#include "debug.h"
#define OPEN freopen(".in", "r", stdin); freopen(".out", "w", stdout);
#define TIME cerr << "\n" << fixed << setprecision(2) << 1000.0 * clock() / CLOCKS_PER_SEC << " milliseconds ";
#else
#define debug(...) void(23)
#define OPEN void(0000)
#define TIME void(232323233)
#endif
void solve()
{
int n; cin >> n;
vector <pair <int, int>> v(n);
int totwt = 0;
for(int i = 0; i < n; i++)
{
int a, b; cin >> a >> b;
totwt += a;
v[i] = {b, i};
}
sort(v.begin(), v.end(), greater <> ());
vector <int> ans(n, 0); int cnt = n;
for(int i = 0; i < n; i++)
{
if(totwt <= v[i].first)
{
ans[v[i].second] = totwt;
totwt = 0;
cnt--;
break;
}
ans[v[i].second] = v[i].first;
totwt -= v[i].first;
cnt--;
}
cout << cnt << "\n";
for(int i : ans) cout << i << " ";
return;
}
int32_t main()
{
OPEN;
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
while(t--)
{
solve();
}
TIME;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |