-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2878.cpp
More file actions
66 lines (50 loc) · 1.16 KB
/
2878.cpp
File metadata and controls
66 lines (50 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
#define MAXN 100050
int N;
vector<unsigned long long> want;
unsigned long long a, M, sum=0;
unsigned long long ans=0;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> M >> N;
for(int i=0 ; i<N ; i++){
cin >> a;
want.push_back(a);
sum += a;
}
sum -= M;
sort(want.begin(), want.end());
for(int i=0 ; i<N ; i++){
unsigned long long dis = min(want[i], sum/(N-i));
sum -= dis;
ans += dis*dis;
}
cout << ans;
}
// 우선순위 큐 이용
// cin >> M >> N;
// for(int i=0 ; i<N ; i++) {
// cin >> a;
// PQ.push(a);
// }
// for(int i=0 ; i<M ; i++){
// int top = PQ.top();
// PQ.pop();
// PQ.push(top-1);
// }
// int size = PQ.size();
// while(!PQ.empty()){
// int top = PQ.top();
// // cout << top;
// if(top>0) ans += pow((unsigned long long)top,2);
// PQ.pop();
// }
// cout << ans;
// }