CodeForces 1992B Angry Monk

题目链接:CodeForces 1992B【Angry Monk】



思路

       找出最大的元素,除了最大的元素的所有元素全部分成1,所以操作次数为sum(数组) - max(数组) - (数组元素个数 - 1),然后全部合并到最大的元素上,操作次数为sum(数组) - max(数组),所以最最后得到sum(数组) * 2 - max(数组) * 2 - (数组元素个数 - 1)


代码

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;

ll a[N];
void solve() {
  ll n, m, maxn = 0, sum = 0;
  cin >> m >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    maxn = max(maxn, a[i]);
  }
  cout << (2 * sum - 2 * maxn - n + 1) << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
posted @ 2024-07-16 14:10  薛定谔的AC  阅读(4)  评论(0编辑  收藏  举报