CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » June 2010 Contest » Squirrel and chestnut

Squirrel and chestnut

Problem code: SQUIRREL

  • All Submissions

All submissions for this problem are available.

There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after Ti second(s), and one more every Pi second(s) after that. The “big mama” of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.

Request

Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.

Input

 

  • The first line contains an integer t, the number of test cases, for each:
    • The first line contains the integers m,n,k, respectively.
    • The second line contains the integers Ti (i=1..m), respectively.
    • The third line contains the integers Pi (i=1..m), respectively.
  • (Each integer on a same line is separated by at least one space character, there is no added line between test cases)

 

Output

For each test cases, output in a single line an integer which is the shortest time calculated.

Example

Input:

2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1

Output:

4
3

* Explain (case #1): 2 squirrels waiting below the trees 2 and 3.

Limitations

  • 0<t?20
  • 0<m,n?10,000
  • 0<k?107
  • 0<Ti,Pi?100


Author: anhdq
Date Added: 5-05-2010
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

The input does not satisfy

triplem @ 1 Jun 2010 03:20 PM

The input does not satisfy the constraints provided. Which have missing symbols again, as well.

There are issues with several

pieguy @ 1 Jun 2010 03:22 PM

There are issues with several of the problem statements.  For this problem, the input begins with an integer giving number of cases, then each case is as described, but m and n can be up to 10000

and time limit seems to not

Arazel @ 1 Jun 2010 03:45 PM

and time limit seems to not be 2s ?

looks like time limit is not

atul agrawal @ 1 Jun 2010 04:06 PM
looks like time limit is not 2 seconds

The time limit is two

triplem @ 1 Jun 2010 04:07 PM

The time limit is two seconds.

if time limit is 2s then how 

shishir @ 1 Jun 2010 05:19 PM

if time limit is 2s then how  solutions are accepted ,those took more than 2s(2.03-3.61)??

@ shishir  there can be

Shr33 @ 1 Jun 2010 05:27 PM

@ shishir  there can be multiple files

does the value of time is

psbbboyz @ 1 Jun 2010 05:31 PM

does the value of time is limited by something( ie does it fit into a long?)

here num of squirrels <= num

dejavu @ 1 Jun 2010 05:39 PM

here num of squirrels <= num of tress right ?? if not what happens when many squirrels are under same tree

Time limit for each case is

Sreenath @ 1 Jun 2010 05:45 PM

Time limit for each case is 2s. The displayed time is total time for all the testcases.

@Ankit Think what will happen

psbbboyz @ 1 Jun 2010 05:50 PM

@Ankit

Think what will happen and you will arrive at the answer

One squirrel can carry any

corile @ 1 Jun 2010 07:45 PM

One squirrel can carry any number of chestnuts, right?

will many squirrels under the

sankikhopadi @ 1 Jun 2010 08:05 PM

will many squirrels under the same tree make any difference??...there is no maximum capacity for squirrel so i think 1 squirrel per tree is same is many under the same...

@vishal question is

imrankane2005 @ 1 Jun 2010 08:18 PM

@vishal question is sufficient to answer your query.

i  am again and again gettin

raman bhatia @ 1 Jun 2010 08:30 PM

i  am again and again gettin runtime error- segmentation faults.. i have used arrarys of sizes 777 (3 arrays) and m takin input using the getchar function... (as is necessary acc to the problems) should i initialize them to zero in order to prevent this error from arising?? although they work absolutely fine at my pc
please help me out people, i am a newbee.

@Raman: The problem statement

pieguy @ 1 Jun 2010 08:40 PM

@Raman: The problem statement was changed.  777 is not the upper limit, 10000 is.

@David.. thanks , i changed

raman bhatia @ 1 Jun 2010 08:56 PM

@David.. thanks , i changed it, but it is still showing a run time error

@Raman: I responded your

pieguy @ 1 Jun 2010 09:36 PM

@Raman: I responded your first question because it was directly related to a mistake in the problem statement, however you really shouldn't have asked the question in the first place because it is a violation of the contest rules to help or be helped by others, or discuss solving strategies of any kind.

@David.. oh m sry man.. i

raman bhatia @ 1 Jun 2010 10:55 PM

@David.. oh m sry man.. i became a member yesterday.. not aware  d d rules :)

I am unable to submit

nitin.nizhawan @ 1 Jun 2010 11:17 PM

I am unable to submit solution, anyone facing the same issue? when the submit request takes a long time to respond and returns back to same page with no sumbissions made.

i am using firefox, is it

nitin.nizhawan @ 1 Jun 2010 11:19 PM

i am using firefox, is it supported?

squirrels are standing under

cooltodinesh @ 1 Jun 2010 11:30 PM

squirrels are standing under trees. Can they move from one tre to another.

once a squirrel stand below one tree, does it hve to stand below same till last?

sorry i got the ans. i didnt

cooltodinesh @ 1 Jun 2010 11:33 PM

sorry i got the ans. i didnt read nealy first. :)

I am still unable to submit

nitin.nizhawan @ 1 Jun 2010 11:34 PM

I am still unable to submit any solution. HELP!!!!! PLEASE!!!!!!!!!!!!!!!!!

@Dinesh Salve: "and the

anhdq_adm @ 2 Jun 2010 07:07 AM

@Dinesh Salve: "and the squirrels move nowhere after that"

the time limit is 1 sec..

raman bhatia @ 2 Jun 2010 11:52 AM

the time limit is 1 sec.. come on!!

when does it give runtime

rebhu @ 2 Jun 2010 02:43 PM

when does it give runtime error(other)?

I am using only 2.46M but still its giving the same error.

admin help i have done the

mimo91 @ 2 Jun 2010 02:48 PM

admin help

i have done the code and it makes the output in a correct way but it tells me wrong answer

hey earlier time limit was 2

root5 @ 2 Jun 2010 04:02 PM

hey earlier time limit was 2 sec..come on..time limit only 1 sec?

The time limit was actually 1

pieguy @ 2 Jun 2010 05:11 PM

The time limit was actually 1 second the entire time, but incorrectly being displayed as 2 seconds.

If my code was accepted, can

saintqdd @ 2 Jun 2010 05:51 PM

If my code was accepted, can i resubmit?  I want to improve my rank

i dont know whats the

tpawan @ 2 Jun 2010 05:59 PM

i dont know whats the problem

the values for which  i m testing my code to its giving right o/p

but in the result its showing wrong ans

plz sm1 help

thank you

The time limit is for all the

drohit @ 2 Jun 2010 11:58 PM

The time limit is for all the test cases or is it for only one????

 

@Durvasula Rohit: 1s for a

anhdq_adm @ 3 Jun 2010 04:24 AM

@Durvasula Rohit: 1s for a set of all T test cases ;-)

my ans for above test case

rajul884 @ 3 Jun 2010 10:40 AM

my ans for above test case are coorect but it stilll give me run time error .

what about if no of squirrel >no of nut tree

how come people are

drohit @ 3 Jun 2010 11:55 AM

how come people are getting 3-4 sec when the time limit is only 1 sec!!!!!

Because they read

triplem @ 3 Jun 2010 12:05 PM

Because they read instructions like 'Have you browsed through the FAQ?' that appears below 'Post new comment' :P

time limit exceeding every

braintorrent @ 3 Jun 2010 10:56 PM

time limit exceeding every time..

what to do..

Comment edited by Admin.

TeamCyclone @ 4 Jun 2010 01:14 AM

Comment edited by Admin.

  • Delete

@TeamCyclone: You are not

admin @ 4 Jun 2010 01:25 AM

@TeamCyclone: You are not supposed to post code. You will be banned if you further violate the rules!

Извините

TeamCyclone @ 4 Jun 2010 01:34 AM
Извините
  • Delete

what happen if n>m? getting

codegambler @ 6 Jun 2010 07:43 AM
what happen if n>m? getting WA even in brute force also:((

sorry if above is discussion

codegambler @ 6 Jun 2010 07:51 AM

sorry if above is discussion of any statagy to approach to problem. Anyway this will surly give TLE if it gives corrcet answer. But i just want to know for n>m.

The problem statement isn't

triplem @ 6 Jun 2010 08:30 AM

The problem statement isn't really specific enough so I think it is fine to answer that. I guess squirrels can choose the same tree. But all but one of those who do would end up not doing much.

I don't understand the

codegambler @ 6 Jun 2010 09:56 AM

I don't understand the mistake in my WA code and ACCEPTED code. I request to discuss it after end of contest.

sorry now i understood my

codegambler @ 6 Jun 2010 01:48 PM
sorry now i understood my mistake

I am getting a runtime error,

gaurav.sgr @ 6 Jun 2010 05:28 PM

I am getting a runtime error, Kindly help i am new.

@Stephen Merriman: they can

anhdq_adm @ 6 Jun 2010 09:55 PM

@Stephen Merriman: they can stay at a same tree, but the number of squirrels they will get in total stay the same too!

@Pankaj kumar: thanks for realizing your error, so it is better for everyone to check your code before asking, since in fact this problem is having the highest number of AC codes. :-)

I am a newbie to this

tanleech @ 10 Jun 2010 10:25 AM

I am a newbie to this contest.

i am having a runtime error. May I know what's the memory limitation ? and any tips to minimise the memory usage.

I'm afraid there's not much

triplem @ 10 Jun 2010 11:36 AM

I'm afraid there's not much more anyone can do while the contest is on but suggest you read the FAQ.

I submitted my solution 2nd

kumaran @ 10 Jun 2010 04:16 PM

I submitted my solution 2nd time and got better time....but there is no update in the rank list...why so?

now that the challenge has

sanjayk @ 11 Jun 2010 04:31 PM

now that the challenge has ended. could someone give me a hint on the p'ble soln. I tried creating a sequence on  on first n series ( with least Pi + Ti) , but, my soln gives TLE.  Would appreciate any hint

I used binary search. Given a

triplem @ 11 Jun 2010 04:38 PM

I used binary search. Given a particular moment in time, calculate how many chestnuts each tree has dropped, sort, and add up the N biggest values. If that is at least k, that time is an upper limit, else it is a lower limit.

do you think using a scanf

sanjayk @ 11 Jun 2010 04:40 PM

do you think using a scanf for each Pi and Ti would make my soln slower?

@sanjay: no, not that. you

jvimal @ 11 Jun 2010 10:15 PM

@sanjay: no, not that. you have to read in all the input anyway.  After T seconds, there would be Ni = max(0, 1+(T-Ti)/Pi) nuts. And you need to find the smallest T for which the top N trees (or M trees, if M < N) sum to at least k nuts.

Straight forward way is to check for T=0, 1, ...; but that will take a lot of time.  You use binary search to find that minimum T because the sum of nuts under the top min(N,M) trees will be always increasing. (monotone property.)

check top 7 accepted

shishir @ 12 Jun 2010 01:55 PM

check top 7 accepted solutions for this case:

1

3 2 4

1 2 23

20 20 2

answer shold be 22 but u'll get surprise to see ;AC solutions will give different answers(but not 22 :p).

codechef needs to improve their test cases quality.

^ if you're including my

f03nix @ 12 Jun 2010 05:13 PM

^ if you're including my solution in the list ... i hope you commented the line 26 (freopen). :)

Plus , others could be using some sort of buffering technique ... which can give unexpected results when the input isn't fed from a file.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com