RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00154

Ljutnja

Gold II 골드 II
난이도
1s
시간 제한
32MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Children in a kindergarten have received a large sack containing \(M\) candies. It has been decided that the candies are to be distributed among \(N\) children.

Each child has stated the number of candies that it wants. If a child isn't given the amount of candy it wants, it will get angry. In fact it'll get angrier for each candy it is deprived of. Some speculate that its anger will be equal to the square of the number of candy it is deprived of. For instance, if Mirko states that he wants \(32\) candies but receives only \(29\), he would be missing \(3\) candies, so his anger would be equal to \(9\).

Unfortunately, there is an insufficient amount of candy to satisfy all children. Therefore, the candies should be distributed in such a way that the sum of the children's anger is minimal.

제약

Test cases worth 40% of total points have M not greater than 200 000.
Test cases worth 70% of total points have no child state that it wants more than 100 000 candies.
Test cases worth 80% of total points have at least one of the above stated constraints will be met.

입력 형식

The first line contains two integers, \(M\) (\(1 \le M \le 2 \cdot 10^9\)) and \(N\) (\(1 \le N \le 100\,000\)).

The following \(N\) lines contain integers (one per line) which represent the wishes of the children. Those numbers are all strictly less than \(2 \cdot 10^9\), and their sum always exceeds \(M\).

출력 형식

The first and only line of output must contain the minimum sum of the children's anger.

Note: The test cases will ensure that the result fits in a 64-bit unsigned integer: int64 in Pascal, long long in C/C++, long in Java.

Scoring: Test cases worth \(40\%\) of total points have \(M\) not greater than \(200\,000\). Test cases worth \(70\%\) of total points have no child state that it wants more than \(100\,000\) candies. Test cases worth \(80\%\) of total points have at least one of the above stated constraints met.

서브태스크
서브태스크점수설명

Test 1

10점

None

Test 2

10점

None

Test 3

10점

None

Test 4

10점

None

Test 5

10점

None

Test 6

10점

None

Test 7

10점

None

Test 8

10점

None

Test 9

10점

None

Test 10

10점

None

예제 1
입력
5 3
1
3
2
출력
1
예제 2
입력
10 4
4
5
2
3
출력
4
문제 정보

riseoj 작성

출처 COCI 2010/2011 Contest 1

평가 및 의견

Ljutnja

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Ljutnja

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8