How to fix Run-Error issue? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to fix Run-Error issue?

The online Judge in my school says that my code has a run-error issue, even though the input and output of the code are already correct. How do i fix this? Sample Input : 3 5 1 2 3 4 5 4 4 4 4 4 3 10 1 2 Sample output : Case #1: 9 Case #2: 8 Case #3: 12 My code : #include<stdio.h> int main(){ int t; long int n = 0, max1, max2, v[100]; scanf("%d", &t); for(int i=1; i<=t; i++){ if(t>=1 && t<=10){ scanf("%ld", &n); } if(n>=2 && n<=1000000){ for(long int j=0; j<n; j++){ scanf("%ld", &v[j]); } if (v[0] > v[1]) { max1 = v[0]; max2 = v[1]; } else { max1 = v[0]; max2 = v[1]; } for(long int j=2; j<n; j++) { if (v[j] > max1) { max2 = max1; max1 = v[j]; } else if (v[j] > max2) { max2 = v[j]; } } long int sum=max1+max2; printf("Case #%d: ", i); printf("%ld\n", sum); } } return 0; } Thank you in advance!

25th Oct 2020, 8:06 AM
Choutato
Choutato - avatar
2 Answers
+ 10
Input and output is sometimes a bottleneck in the program. The following lines at the beginning of the code make input and output more efficient: ios::sync_with_stdio(0); cin.tie(0); For more clear explanation- https://stackoverflow.com/questions/31162367/significance-of-ios-basesync-with-stdiofalse-cin-tienull
25th Oct 2020, 8:32 AM
Aditya
Aditya - avatar
+ 1
@EnCoDeR Thank you very much!
25th Oct 2020, 11:34 AM
Choutato
Choutato - avatar