結果

問題 No.1279 Array Battle
ユーザー oooooba
提出日時 2021-07-02 22:23:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 1,152 ms
コンパイル使用メモリ 121,644 KB
最終ジャッジ日時 2025-01-22 16:17:44
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int32_t n;
    cin >> n;
    vector<pair<int32_t, int32_t>> ais(n);
    for (auto i = 0; i < n; ++i) {
        int32_t a;
        cin >> a;
        ais[i] = {a, i};
    }
    vector<int32_t> bs(n);
    for (auto &&b : bs) {
        cin >> b;
    }
    sort(ais.begin(), ais.end());
    int32_t max_s = -1, ans = 0;
    do {
        int32_t s = 0;
        for (auto i = 0; i < n; ++i) {
            s += max(ais[i].first - bs[i], 0);
        }
        if (s == max_s)
            ++ans;
        else if (s > max_s) {
            max_s = s;
            ans = 1;
        }
    } while (next_permutation(ais.begin(), ais.end()));
    cout << ans << endl;
    return 0;
}
0