← Back to topics
Topic

BOI-bins

h
harta01
hint 1: you can solve it in O(M*N)
hint 2: since M is small, you can count the number of occurrence of x so that you don't need to do sorting all the time
M
MilosRadic
yea i solved it and got in best times thanks so much for the hint:D
just a quest why cant my code pass in c(it gives 14/20) and in c++ it passes normally:S
i am new to c and c++
my 5th program in these languages:D
PS go resubmit operacije it is fixed now
h
harta01
for task operacije, I just want to try your checker, test cases and other things, but I don't realize that it's published that's why I got so many WA's. I myself have not tried it..
h
harta01
your array niz is too small, since you start from 1 instead of 0 so you need at least niz[20001]. or something bigger than 20000. try it dunno if that's the case :)
M
MilosRadic
so in c arrays start from 1?
can i make an array start at any number less than 0
like in pascal u can have array -3..5 or smt
d
didins
In C, an array that is declared to have the length of N will have elements in the range of 0..N--1. You cannot make it start from, for example, -2, but you could just calculate the indexes like it started from -2 and than add 2 to them.

Hope I helped.
p
picsel
You can do this

int niz[10000];
int *pok=niz+5000;

Now you can use all values from pok[-5000] to pok[4999]
h
halil
So simple and elegant
h
harta01
you can try this:
int niz[10000];
#define niz (niz + 5000)

Edit: beaten xD