-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-3.cpp
More file actions
57 lines (49 loc) · 927 Bytes
/
7-3.cpp
File metadata and controls
57 lines (49 loc) · 927 Bytes
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
/**
* @file 7-3.cpp
* @brief 떡볶이 떡 만들기
* @author Sam Kim (samkim2626@gmail.com)
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
int num;
cin >> num;
v.push_back(num);
}
int start = 0;
int end = *max_element(v.begin(), v.end());
int rst = 0;
while (start <= end)
{
int total = 0;
int mid = (start + end) / 2;
for (auto &&i : v)
{
if (i > mid)
{
total += i - mid;
}
}
if (total < m)
{
end = mid - 1;
}
else
{
rst = mid;
start = mid + 1;
}
}
cout << rst << '\n';
return 0;
}