10300 - Ecological Premium

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Eng_XD
New poster
Posts: 1
Joined: Mon Aug 10, 2009 5:33 pm

Time limit exceeded

Post 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;
}
sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: Time limit exceeded

Post 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--;
}

Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
captain_jyoti
New poster
Posts: 1
Joined: Tue Nov 16, 2010 5:32 am

Re: 10300 - Ecological Premium

Post by captain_jyoti »

Use
int main()
{
.....

return 0;
}


instead of void main(void)

Online Judge don't support void main()
dream
New poster
Posts: 3
Joined: Sat Feb 19, 2011 4:40 pm

10300 ecological premium

Post 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;
}
tamjidahmed
New poster
Posts: 2
Joined: Tue Aug 09, 2011 7:19 pm

10300 - Ecological Premium

Post 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;
}
doordie2009
New poster
Posts: 1
Joined: Fri Nov 25, 2011 7:08 pm

Re: 10300 ecological premium

Post by doordie2009 »

you need not to check

Code: Select all

while(scanf("%li",&f)!=EOF)
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!
luijhy_9234
New poster
Posts: 4
Joined: Wed Nov 13, 2013 8:47 pm

Re: 10300 ecological premium

Post by luijhy_9234 »

AC,thanks
Last edited by luijhy_9234 on Thu Apr 03, 2014 12:47 am, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10300 ecological premium

Post by brianfry713 »

print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 103 (10300-10399)”