Submission #199503

#TimeUsernameProblemLanguageResultExecution timeMemory
199503SamAndPod starim krovovima (COCI20_psk)C++17
50 / 50
6 ms376 KiB
#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)

psk.cpp: In function 'int main()':
psk.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
psk.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i].a, &a[i].b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...