# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199503 | SamAnd | Pod starim krovovima (COCI20_psk) | C++17 | 6 ms | 376 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.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |