### Shayan.To's blog

By Shayan.To, 9 years ago, I can not understand why my code make wrong answer for the last test. my algorithm is same as editorial and my code is like some others that I have seen. The question is 508C - Anya and Ghosts. the C problem of last contest. and my code: 9606896

int m, t, r;

int wr;

bool can;

int num;

int res = 0;

int main() {

cin >> m >> t >> r;

For(i, 0, m)
{
cin >> wr[i];
wr[i] += 304;
}

int now, need, j;
if (t >= r)
{
For(i, 0, m)
{
now = wr[i];
need = r - num[now];
for (int l = 1; l <= t; l++)
{
if (need <= 0)
break;
j = now &mdash; l;
if (can[j] != true)
{
can[j] = true;
res++;
need--;
For(k, 0, t)
{
num[j + 1 + k]++;
}

}

}

if (need > 0)
{
cout << -1 << '\n';
return 0;
}
}
cout << res << '\n';
return 0;
}

cout << -1 << '\n';
return 0;


}  Comments (4)
 » 9 years ago, # | ← Rev. 3 →   Just increase size:int wr; bool can; int num;9611486
•  » » Thanks so much! can you explain why?
•  » » » If i = 299 then now = 604, j can be > 600, j+k+1 can be > 900
•  » » » » Thanks so much :):):):):)