시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 563 291 266 53.629%

문제

경래는 닭을 기르는데 올 겨울 달걀 풍년으로 함박 웃음을 짓고 있다. 그리고 이 달걀을 영양란으로 둔갑하여 옥션에 판매하려한다.

경래는 총 N개의 달걀이 있고, 그의 잠재적인 고객은 총 M명이다. 그리고 각각의 i번째 고객은 각자 달걀 하나를 Pi 가격 이하로 살 수 있다고 밝혔다.

경래는 영양란이라 속인 죄책감에 한 고객에게 두 개 이상의 달걀은 팔지 않기로 하였다. 하지만 위의 규칙 하에 수익은 최대로 올리고 싶기에 얼마로 팔지 고민하고 있다. 즉, A가격에 달걀을 판다고 하면 Pi가 A가격보다 크거나 같은 모든 고객은 달걀을 산다는 뜻이다. (물론 달걀 총 수량을 초과하여 팔 수 는 없다)

문제는 이러한 경래를 도와 최대 수익을 올릴 수 있는 달걀의 가장 낮은 가격을 책정하는 것이다.

입력

첫째 줄에 정수 N(1≤N≤1,000)과 M(1≤M≤1,000)이 입력된다. 둘째줄부터 M+1번째 줄까지 i+1번째 줄에는 Pi(1≤Pi≤1,000,000)가 입력된다.

출력

첫째 줄에 경래가 책정한 가격과 이 가격으로 올릴 수 있는 수익을 출력한다.

예제 입력 1

5 4
2
8
10
7

예제 출력 1

7 21
W3sicHJvYmxlbV9pZCI6IjEyNDYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWM2MjhcdWI3N2NcdWM3NzggXHVkMzEwXHViOWU0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWFjYmRcdWI3OThcdWIyOTQgXHViMmVkXHVjNzQ0IFx1YWUzMFx1Yjk3NFx1YjI5NFx1YjM3MCBcdWM2MmMgXHVhY2E4XHVjNmI4IFx1YjJlY1x1YWM0MCBcdWQ0OGRcdWIxNDRcdWM3M2NcdWI4NWMgXHVkNTY4XHViYzE1IFx1YzZjM1x1Yzc0Y1x1Yzc0NCBcdWM5ZDNcdWFjZTAgXHVjNzg4XHViMmU0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Y2UgaGUgc2hvdWxkIHNldCBvbiBhIGxvdCBvZiBoYXkgdG8gbWF4aW1pemUgdGhlIGFtb3VudCBvZiBtb25leSBoZSBtYWtlcy48XC9wPlxyXG4iLCJpbnB1dCI6IjxwPiogTGluZSAxOiBUd28gc3BhY2Utc2VwYXJhdGVkIGludGVnZXJzOiBOIGFuZCBNPFwvcD5cclxuXHJcbjxwPiogTGluZXMgMi4uTSsxOiBMaW5lIGkrMSBjb250YWlucyBhIHNpbmdsZSBpbnRlZ2VyOiBQX2k8XC9wPlxyXG4iLCJvdXRwdXQiOiI8cD4qIExpbmUgMTogVHdvIHNwYWNlLXNlcGFyYXRlZCBpbnRlZ2VyczogdGhlIHNtYWxsZXN0IHByaWNlIHRoYXQgRmFybWVyIEpvaG4gc2hvdWxkIGNob29zZSB0byBtYXhpbWl6ZSBoaXMgcmV2ZW51ZSBhbmQgdGhlIGFtb3VudCBvZiBtb25leSBoZSB0YWtlcyBpbi48XC9wPlxyXG5cclxuPHA+Jm5ic3A7PFwvcD5cclxuIiwiaGludCI6IiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

Olympiad > USA Computing Olympiad > 2008-2009 Season > USACO November 2008 Contest > Bronze 3번