CCC '13 J4 - Time on task

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
Canadian Computing Competition: 2013 Stage 1, Junior #4

You have been asked by a parental unit to do your chores.

Each chore takes a certain amount of time, but you may not have enough time to do all of your chores, since you can only complete one chore at a time. You can do the chores in any order that you wish.

What is the largest amount of chores you can complete in the given amount of time?

Input Specification

The first line of input consists of an integer (), which is the total number of minutes you have available to complete your chores.

The second line of input consists of an integer (), which is the total number of chores that you may choose from. The next lines contain the (positive integer) number of minutes required to do each of these chores. You can assume that each chore will take at most minutes.

Output Specification

The output will be the maximum number of chores that can be completed in time .

Sample Input 1

6
3
3
6
3

Output for Sample Input 1

2

Explanation of Output for Sample Input 1

Chores must be completed in at most 6 minutes. There are 3 chores available. The first chore takes 3 minutes. The second chore takes 6 minutes. The third chore takes 3 minutes. The answer is 2 since only 2 of these chores can be completed in 6 minutes of time. Specifically, the first and last chore can be completed in the allowable time. It is not possible to complete all 3 chores in 6 minutes.

Sample Input 2

6
5
5
4
3
2
1

Output for Sample Input 2

3

Explanation of Output for Sample Input 2

Tasks 3, 4, and 5 can be completed in 6 minutes. It is not possible to complete more than 3 tasks in 6 minutes.

• commented on Sept. 24, 2020, 8:38 p.m. edited

Could someone help me with my code? I can't find anything wrong, but it's giving me IR's

• commented on Aug. 14, 2020, 7:20 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on March 21, 2020, 6:45 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on July 25, 2019, 11:07 a.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on Jan. 4, 2015, 7:15 p.m.

C is 5 but there are six lines below C.

• commented on Jan. 4, 2015, 8:23 p.m.

Fixed.