문제 링크

www.acmicpc.net/problem/18111' target="_blank">https://www.acmicpc.net">www.acmicpc.net/problem/18111




아래는 제 답변입니다 안풀리는데 테스트케이스는 다되고

인터넷에 찾아봐도 푼사람들이랑 뭐가 차이나는지 잘모르겟어요



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
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REMOVE 2 // 블록 제거
#define PUT 1 // 블록 올리기
int main()
{
int N, M, OriginB, temp;
int min = 257, max = -1;
vector<int> ground;
pair<int, int> result = make_pair(2147483647, 0);
cin >> N;
cin >> M;
cin >> OriginB;
// 입력받은 횟수만큼 블록 추가 min,max 설정
for (int i = 0; i < N; ++i)
{
for (int k = 0; k < M; k++)
{
cin >> temp;
ground.push_back(temp);
if (temp > max) max = temp;
if (temp < min) min = temp;
}
}
// min, max를 이용해 가장 낮은 블록부터 가장 높은 블록까지 모두 계산
// height -> 목표 높이
int height = min;
while (height <= max)
{
int B = OriginB; // 최초 가지고있던 블록
int time = 0; // 소요한 시간
// 모든 블록을 순회해서 height와의 차이만큼 쌓거나 제거함
// time 소요시간만큼 누적
for (int i = 0; i < (int)ground.size(); ++i)
{
int dif = height - ground[i];
if (dif < 0)
{
time += abs(dif) * REMOVE;
++B;
}
else if (dif > 0)
{
time += dif * PUT;
--B;
}
}
// 남은 블록의 개수가 0 이상일때만 기록
if (B >= 0)
{
// 기존 기록보다 소요시간이 적으면 다시 기록
// height는 항상 현재가 더 높다 (min에서 ++)
if (result.first >= time)
{
result.first = time;
result.second = height;
}
}
++height;
}
// 결과값 출력
cout << result.first << " " << result.second;
return 0;
}
cs