https://www.acmicpc.net/problem/2512
#include <cstdio>#include <algorithm>#pragma warning(disable:4996)#define MAX 10000using namespace std;int numOfCity;int city[MAX + 1];int main(){int sum = 0, result = 0, i = 0;scanf("%d", &numOfCity);for (int i = 0; i < numOfCity; i++)scanf("%d", &city[i]);int Budget = 0;scanf("%d", &Budget);sort(city, city + numOfCity);for (i = 0; i < numOfCity; i++){if (sum + (city[i] * (numOfCity - i)) >= Budget){result = (Budget - sum) / (numOfCity - i);break;}elsesum += city[i];}if (i == numOfCity)result = city[numOfCity - 1];printf("%d\n", result);return 0;}
'알고리즘 풀이' 카테고리의 다른 글
백준 9012번 괄호 (0) | 2018.05.05 |
---|---|
백준 2805번 나무자르기 (0) | 2018.04.17 |
백준 1259번 팰린드롬 수 (0) | 2018.04.08 |
백준 7576번 토마토 (0) | 2018.04.03 |
백준 5567번 결혼식 (0) | 2018.03.25 |