Can anyone solve this runtime error?
Status :Time limit exceeded
Time:
5 secs
Memory:
5.368 Mb
Input
4 8 4
1 2 1 2 5
3 5 1 3 4
1 2 4 5 11
1 1 1 3 12
Runtime Error
SIGTSTP
#include <iostream>
using namespace std;
int main() {
// your code goes here
int n,m,k,cert=0;
cin>>n>>m>>k;
int a;
for(int z=0;z<n;z++)
{
int sum=0;
for(int i=0;i<k;k++)
{
cin>>a;
sum+=a;
}
cin>>a;
if(sum>=m && a<=10)
cert++;
}
cout<<cert;
return 0;
}
It's because your code runs for a very long time.
Look at this loop:
for (int i = 0; i < k; k++) {
k
will increase, while i
stays at 0
so i < k
will always be true
.
When k
at some point reaches its limit, INT_MAX
, and you do k++
, it'll will cause signed integer overflow and the program therefore has undefined behavior.
Without knowing what your code is supposed to do, it's not possible to give an exact advice how to make it work, but I suspect that you want this instead:
for (int i = 0; i < k; i++) {