1044. Shopping in Mars (25)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once andsomeofthe diamonds are taken off the chain one by one. Once a diamond is off the chain, it cannot be taken back. For example, if we have a chain of8 diamonds with values M$3, 2, 1, 5, 4, 6, 8, 7, and we must pay M$15. We may have 3 options:
1. Cut the chain between4and6, and take off the diamonds fromthe position 1to5 (with values 3+2+1+5+4=15).
2. Cut before5orafter6, and take off the diamonds fromthe position 4to6 (with values 5+4+6=15).
3. Cut before8, and take off the diamonds fromthe position 7to8 (with values 8+7=15).
Now giventhe chain of diamond values andthe amount that a customer has to pay, you are supposed tolist all the paying options forthe customer.
If itis impossible to pay the exact amount, you must suggest solutions with minimum lost.
Input Specification:
Each input filecontains one test case. For each case, thefirst line contains2 numbers: N (<=105), the total numberof diamonds onthe chain, and M (<=108), the amount thatthe customer has to pay. Then the next line contains N positive numbers D1 ... DN (Di<=103for all i=1, ..., N) which are the values ofthe diamonds. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print "i-j"in a line for each pair of i <= j such that Di + ... + Dj = M. Note thatif there are more than one solution, all the solutions must be printed in increasing order of i.
If there is no solution, output "i-j"for pairs of i <= j such that Di + ... + Dj > M with (Di + ... + Dj - M) minimized. Again all the solutions must be printed in increasing order of i.
It is guaranteed thatthe total value of diamonds is sufficient to pay thegiven amount.
Sample Input 1:
161532154687161015119121413
Sample Output 1:
1-54-67-811-11
Sample Input 2:
51324579
Sample Output 2:
2-44-5