-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18111.cpp
More file actions
55 lines (50 loc) · 1.19 KB
/
18111.cpp
File metadata and controls
55 lines (50 loc) · 1.19 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int N,M,B;
cin>>N>>M>>B;
vector<vector<int>> mine(N,vector<int>(M,0));
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
cin>>mine[i][j];
}
}
int t=INT_MAX,max_b=0;
for(int i=0;i<=256;i++){
int tempB=B,tempT=0;
bool p=true;
for(int j=0;j<N;j++){
for(int k=0;k<M;k++){
if(mine[j][k]>i){
tempB+=mine[j][k]-i;
tempT+=2*(mine[j][k]-i);
}
}
}
for(int j=0;j<N;j++){
for(int k=0;k<M;k++){
if(mine[j][k]<i){
if(tempB<i-mine[j][k]){
p=false;
break;
}
tempB-=i-mine[j][k];
tempT+=i-mine[j][k];
}
}
if(!p) break;
}
if(p&&(t>tempT||t==tempT&&max_b<i)){
t=tempT;
max_b=i;
}
}
cout<<t<<' '<<max_b;
return 0;
}