Submission #111227

# Submission time Handle Problem Language Result Execution time Memory
111227 2019-05-14T10:49:29 Z kingfran1907 Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5+10;

int n, m;
long long k;
int niz[maxn];

long long cost(int x, int y) {
    int med = niz[(x + y) / 2];

    long long out = 0;
    for (int i = x; i <= y; i++)
        out += abs(niz[i] - med);

    return out;
}

int main() {
    scanf("%d%d%lld", &n, &m, &k);

    for (int i = 0; i < n; i++)
        scanf("%d", niz+i);
    sort(niz, niz+n);

    int ptr = 0, sol = 0;
    long long tren = 0;
    for (int i = 0; i < n; i++) {
        int med = (i + ptr) / 2;
        while (ptr < n - 1) {
            int newmed = (i + ptr + 1) / 2;
            long long cp = tren;
            if (med != newmed) {
                tren += (med - i) * (niz[newmed] - niz[med]);
                tren -= (ptr - 1 - med) * (niz[newmed] - niz[med]);
            }
            ptr++;
            med = newmed;
            tren += niz[ptr] - niz[med];
            if (tren > k) {
                ptr--;
                tren = cp;
                break;
            }
        }
        //printf("%d %d -> %lld (%lld)\n", i, ptr, tren, cost(i, ptr));
        sol = max(sol, ptr - i + 1);

        int newmed = (i + 1 + ptr) / 2;
        if (med != newmed) {
            tren += (med - i) * (niz[newmed] - niz[med]);
            tren -= (ptr - newmed) * (niz[newmed] - niz[med]);
        }
        tren -= niz[newmed] - niz[i];
    }
    printf("%d", sol);
    return 0;
}

Compilation message

ricehub.cpp: In function 'int main()':
ricehub.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%lld", &n, &m, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ricehub.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", niz+i);
         ~~~~~^~~~~~~~~~~~~
/tmp/ccrZFgcU.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc7zpDMn.o:ricehub.cpp:(.text.startup+0x0): first defined here
/tmp/ccrZFgcU.o: In function `main':
grader.cpp:(.text.startup+0x92): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status