https://www.acmicpc.net/problem/2805
#include <cstdio>#include <cmath>#include <algorithm>#pragma warning(disable:4996)#define MAX 1000000using namespace std;long long N, M;long long tree[MAX + 1];int main(){scanf("%lld %lld", &N, &M);for (int i = 0; i < N; i++)scanf("%lld", &tree[i]);std::sort(tree, tree + N);long long left = 1;long long right = tree[N - 1];long long result = 0;while (left <= right){long long mid = left + (right - left) / 2;long long len = 0;for (int i = 0; i < N; i++){if (tree[i] > mid)len += ( tree[i] - mid );}if (len >= M){if (result < mid)result = mid;left = mid + 1;}elseright = mid - 1;}printf("%lld\n", result);return 0;}ㅂ
'알고리즘 풀이' 카테고리의 다른 글
백준 1931번 회의실 배정 (0) | 2018.05.07 |
---|---|
백준 9012번 괄호 (0) | 2018.05.05 |
백준 2512번 예산 (0) | 2018.04.16 |
백준 1259번 팰린드롬 수 (0) | 2018.04.08 |
백준 7576번 토마토 (0) | 2018.04.03 |