公式
D - Decrease 2 max elements 解説
by
D - Decrease 2 max elements 解説
by
Cyanmond
シミュレーションをすることで、この問題を解くことができます。\(A\) を降順に並び替える動作は、多くのプログラミング言語で sort
関数として存在します。その他の詳細は以下のコードで確認してください。
実装例 (C++)
#include <bits/stdc++.h>
using namespace std;
int main() {
// input
int n;
cin >> n;
vector<int> a(n);
for (auto &e : a) {
cin >> e;
}
int answer = 0;
while (true) {
// sort
sort(a.begin(), a.end(), greater());
// check condition
if (a[0] == 0 or a[1] == 0) {
break;
}
// apply
a[0] -= 1;
a[1] -= 1;
++answer;
}
// output
cout << answer << endl;
}
投稿日時:
最終更新: