DMPG '15 S1 - Collecting Dust

View as PDF

Submit solution

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

Weiss is the head of a company that exports dust across the continent by train. However, dust can be very unstable (and highly explosive in large quantities). Depending on the type of dust, only a few crates of it can be loaded onto one car. One train in particular will be transporting five types of dust.

To meet safety regulations, one car may carry up to 4 crates of red dust, 5 crates of white dust, 4 crates of black dust, 3 crates of yellow dust, or 6 crates of green dust. Different types of dust cannot be loaded into the same car. It is possible that all dust crates may not fit on the train, in which case there will be no empty cars (but leftover crates).

Given R crates of red dust, W crates of white dust, B crates of black dust, Y crates of yellow dust, and G crates of green dust, how many cars will not be in use on a train with C cars if Weiss loads the train optimally?

Input Specification

The first line of input will contain the single integer C (1 \le C \le 1\,000). The next line of input will contain 5 space-separated integers R, W, B, Y, and G (0 \le R, W, B, Y, G \le 100).

Output Specification

A single integer, the number of empty cars on the train.

Sample Input

8 10 12 10 10

Sample Output



There are no comments at the moment.