-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP18111.cpp
44 lines (40 loc) · 954 Bytes
/
P18111.cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define FOR(i, n) for(int i = 0 ; i < n ; i++)
#define MAXX 987654321
int N, M, B, _B;
int blocks[250000];
int main() {
int timeMin = MAXX;
int heightMax = 0;
scanf("%d %d %d", &N, &M, &_B);
for (int i = 0; i < M*N; i++)
scanf("%d", &blocks[i]);
for (int h = 0; h <= 256; h++) {
B = _B;
int nBlanks = 0, nUp = 0;
long long stackedTime = 0;
for (int i = 0; i < M*N; i++) {
if (blocks[i] < h)
nBlanks += h - blocks[i];
else if (blocks[i] > h)
nUp += blocks[i] - h;
}
if ((B + nUp) < nBlanks) // 0 3 3 3 일때 nBlanks만 3 nUp은 0
break;
stackedTime += nUp * 2;
stackedTime += nBlanks * 1;
if (timeMin == stackedTime) {
heightMax = max(heightMax, h);
}
else if (timeMin > stackedTime) {
timeMin = stackedTime;
heightMax = h;
}
}
printf("%d %d\n", timeMin, heightMax);
return 0;
}