Page 2 of 2
Time limit exceeded
Posted: Mon Aug 10, 2009 5:43 pm
by Eng_XD
I tried to submit my source code of the problem 10300 - Ecological Premium and i got the messenge Time limit exceeded. The run time was 3.00 seconds but the Time limited is 1.00 second, i`ve tried to simplify the algorithm but i failed. I don`t know what i can do. pls Help me.
Source Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int n, f, i, j, sum, space, animals, C;
while (n!=EOF){
scanf ("%d", &n);
for( i=0; i<n; i++){
scanf("%d", &f);
sum=0;
for (j=0; j<f; j++){
scanf("%d%d%d", &space, &animals, &C);
sum+=space*C;
}
printf("%d\n", sum);
}
}
return 0;
}
Re: Time limit exceeded
Posted: Tue Aug 11, 2009 9:31 pm
by sazzadcsedu
Several things to note:
Post title should contain Problem no like(10300-ecological premium) not TLE,WA,CE etc.
so remember this.And dont forget to place your code inside Quote tag;
You have problem in input taking. you program continue taking input,never ends.so TLE occurs.
So take input such a way-
Code: Select all
int ncase; //variable contain no. of cases;
scanf("%d",&ncase);
while(ncase>0)
{
code.................
ncase--;
}
Re: 10300 - Ecological Premium
Posted: Tue Nov 16, 2010 5:46 am
by captain_jyoti
Use
int main()
{
.....
return 0;
}
instead of void main(void)
Online Judge don't support void main()
10300 ecological premium
Posted: Sun Feb 20, 2011 9:42 pm
by dream
i can't find where is the problem .

plz help me.
here is my code:
#include<stdio.h>
int main()
{
unsigned long int size,animal,env,total,n,f;
scanf("%li",&n);
for(int i=1;i<=n;i++)
{
while(scanf("%li",&f)!=EOF)
{total=0;
for(int j=1;j<=f;j++)
{
scanf("%li%li%li",&size,&animal,&env);
total=size*env+total;
}
printf("%li",total);
}
}
return 0;
}
10300 - Ecological Premium
Posted: Tue Aug 09, 2011 8:45 pm
by tamjidahmed
I can't find why I am getting wrong answer...plz help me
(I used C-language)
#include<stdio.h>
int main()
{
unsigned long int a,b,c,i,j,testcase,ans=0,farmer,sum;
scanf("%lu",&testcase);
for (i=0;i<testcase;i++)
{
scanf("%lu",&farmer);
for (j=0;j<farmer;j++)
{
scanf("%lu",&a);
scanf("%lu",&b);
scanf("%lu",&c);
sum=a*c;
ans=ans+sum;
}
printf("%lu",ans);
ans=0;
if(j<farmer-1)
printf("\n");
}return 0;
}
Re: 10300 ecological premium
Posted: Fri Nov 25, 2011 7:15 pm
by doordie2009
you need not to check
As per the problem description your "n" will determine how much test cases are going to give. The code can be written in the following way:
Code: Select all
long long int size,animal,env,total,n,f;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&f);
total=0;
for(int j=1;j<=f;j++)
{
scanf("%lld%lld%lld",&size,&animal,&env);
total=size*env+total;
}
printf("%lld\n",total);
}
Happy Coding!
Re: 10300 ecological premium
Posted: Wed Nov 13, 2013 9:15 pm
by luijhy_9234
AC,thanks
Re: 10300 ecological premium
Posted: Thu Nov 14, 2013 12:33 am
by brianfry713
print a newline char at the end of the last line.