L개의 좌석이 있는 한 줄에 N명 중 정확히 K명을 앉혀 얻을 수 있는 총 만족도의 최댓값을 구한다. 앉은 승객은 A[i]에 더해 양옆 빈 좌석 수만큼 B[i]를 받는다.
어려움8동적 계획법그리디정렬조합론아직 제출이 없습니다시간 제한2초메모리 제한512 MBThe subway in town X is a bit unusual. One train consists of a single wagon and there is a single row of L seats in it. If there are N passengers in the wagon, numbered from 0 to N-1, each passenger gets a certain amount of pleasure as follows:
For example let’s have 3 passengers in the wagon, numbered 0, 1 and 2, and A[0]=5, B[0]=2, A[1]=10, B[1]=1, A[2]=1, B[2]=1. Let the number of seats L=6 and consider the passengers sitting in the following schema: _ 0 _ _ 1 _ (“_” means an empty seat)
Passenger 2 is standing.
In this case:
The total pleasure of all the passengers is equal to 24.
Write program, which, given the number of seats L, the number of passengers N and the pleasure characteristics for each passenger, determines the maximum possible total pleasure for any number of seated passengers between 1 and N.
The first line of the standard input contains two integers – N and L - the number of passengers and the number of seats.
Each of the next N lines contains two non-negative integers – the characteristics А[i] and B[i] for passenger with index i.
Print N lines, the K-th of which contains a single number – the maximum total pleasure that the passengers can get if there are exactly K of them sitting.
(For K > L print 0, because there are no valid configurations of K passengers on L seats )