Div.3 CF 1103A题(贪心)

📅 发布时间:2026/7/19 6:56:26
Div.3 CF 1103A题(贪心) 题目链接https://codeforces.com/contest/2236/problem/A题目大意给定一个数组h现在要求我们给每个h[i]增加x使得每个h[i]相等其中1xk,求出k的最小值题目思路我们可以找到h数组中的最大值ma和最小值mi可以知道最终数组的可能最小值一定是当前ma1那么kma-mi代码如下#include bits/stdc.h using namespace std; //#define int long long #define endl \n void solve() { int n; cin n; int h[n1]; int ma 0; int mi 7; for (int i 1; i n;i){ cin h[i]; ma max(h[i], ma); mi min(h[i], mi); } ma; int res ma - mi; cout res endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cinT; while (T--) { solve(); } return 0; }