ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1131. Copying

Wrong answer 4! Please help!
Posted by Grigorenko Vlad 20 Jun 2012 21:35
#include<stdio.h>

int main(void){
    int n,k,time,n1,i;
    scanf("%d%d",&n,&k);
    i=1;
    n1=1;
    time=0;
    while(n1<k && n1<n){
        n1=n1+i;
        i++;
        time++;
    }
    if(n - n1>0){
        if((n-n1) % k == 0)
            time=time+(n-n1)/k;
        else
            time=time+(n-n1)/k+1;
    }
    printf("%d",time);
return 0;
}
Re: Wrong answer 4! Please help!
Posted by Bogatyr 9 Oct 2012 16:31
Hints:
 1) your while loop condition is not quite right.
2) you are not growing n1 properly in the while loop
3) your "if (n - n1>0)" is not necessary, if n-n1 == 0 then the division result will be zero
4) integer ceiling of x/y can be done in a single step like this: (x + y - 1)/y
5) it's generally a good idea to finish each line of output with a newline character

In general: do some examples on paper, and step through your code in the debugger, or put in a bunch of print statements to follow the progress of the solution, and you'll discover where the problems are.