Submission #199503

# Submission time Handle Problem Language Result Execution time Memory
199503 2020-02-01T17:02:22 Z SamAnd Pod starim krovovima (COCI20_psk) C++17
50 / 50
6 ms 376 KB
#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

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 time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct