I'm new to competitive programming and I participated in Codeforce #653 in which I spent the whole time solving these problems and did not submit any code because of exceeded time limits or wrong answer for test cases. Anyway, it was awesome. I wanted to solve this problem https://codeforces.com/contest/1374/problem/A and wrote this following code.
#include <stdio.h>
int main(){
int i,t,j,k=0;
int x[60000],y[60000],n[60000],prev[60000];
scanf("%d",&t);
for(i=0; i<t; i++){
scanf("%d %d %d",&x[i],&y[i],&n[i]);
}
for(i=0; i<t; i++){
for(j=0, k=0; j<n[i]; j++ , k++){
if(j%x[i]==y[i]){
prev[i]=k;
}
}
}
for(i=0; i<t; i++){
printf("%d",prev[i]);
printf("\n");
}
return 0;
}
Everything was working fine but for some test cases I'm getting different answers. This was the expected output
12339
0
15
54306
999999995
185
999999998
and my output was this,
12339
0
5
54306
999999995
185
999999998
I did not understand why I got 5 instead of 15 keeping all the other outputs correct and also could anyone please help me to optimize the code, its taking too long to compile for large inputs.
Aucun commentaire:
Enregistrer un commentaire