반응형

18111

https://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
#include <iostream>
using namespace std;
 
int main() {
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
 
    int board[501][501= { 0, };
    int m, n;
    long long b;
    int mn = 99999;
    int mx = 0;
    int a[257= { 0, };
    int res = 0;
 
    cin >> m >> n >> b;
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> board[i][j];
            if (mn > board[i][j]) mn = board[i][j];
            if (mx < board[i][j]) mx = board[i][j];
        }
    }
 
 
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < m; j++) {
            a[board[i][j]] += 1;
        }
    }
 
    while (mn < mx) {
        if (mn == mx) break;
        if (b >= a[mn] && a[mn] <= a[mx]*2) {
            res += a[mn];
            b -= a[mn];
            a[mn + 1+= a[mn];
            mn++;
        }
        else {
            res += a[mx] * 2;
            b += a[mx];
            a[mx - 1+= a[mx];
            mx--;
        }
    }
    cout << res << " " << mx;
    return 0;
}
cs

.

.

.

[풀이]

오답률이 꽤 있는 구현 문제.

제한 시간은 넉넉하니 브루트포스로 조건에 맞춰 구현하면 된다.

 

p.s.

문제 이름도 재밌고, 실버 티어에서 연습하기 좋은 문제이다.

반응형

+ Recent posts