eolymp
bolt
Try our new interface for solving problems
Məsələlər

Computers

Computers

Everybody is fond of computers, but buying a new one is always a money challenge. Fortunately, there is always a convenient way to deal with. You can replace your computer and get a brand new one, thus saving some maintenance cost. Of course, you must pay a fixed cost for each new computer you get. Suppose you are considering an n year period over which you want to have a computer. Suppose you buy a new computer in year y, 1<=y<=n Then you have to pay a fixed cost c, in the year y, and a maintenance cost m(y,z) each year you own that computer, starting from year y through the year z, z<=n, when you plan to buy - eventually - another computer. Write a program that computes the minimum cost of having a computer over the n year period. \InputFile The program input is from a text file. Each data set in the file stands for a particular set of costs. A data set starts with the cost c for getting a new computer. Follows the number n of years, and the maintenance costs m(y,z), y=1..n, z=y..n. The program prints the minimum cost of having a computer throughout the n year period. White spaces can occur freely in the input. The input data are correct and terminate with an end of file. \OutputFile For each set of data the program prints the result to the standard output from the beginning of a line.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3
3
5 7 50
6 8
10
Çıxış verilənləri #1
19
Mənbə Southeastern Europe 2007