Submission
Status:
PPP-PPP-PP
Score: 80
User: Winzzwz
Problemset: สูงต่ำในตาราง
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-09 11:32:53
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct h1 {
int i,j,v;
bool operator < (const h1&o) const {
return v < o.v;
}
};
struct h2 {
int i,j,v;
bool operator < (const h2&o) const {
return v > o.v;
}
};
int n,b,nn,ans;
priority_queue <h1> maxheap;
priority_queue <h2> minheap;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> b;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> nn;
maxheap.push({i,j,nn});
minheap.push({i,j,nn});
}
}
while (true) {
h1 mx = maxheap.top();
h2 mn = minheap.top();
if (mx.i != mn.i) {
ans = max(ans,abs(mx.v-mn.v)+2*b);
break;
} else {
ans = max(ans,abs(mx.v-mn.v));
minheap.pop();
}
}
cout << ans;
return 0;
}