結果

問題 No.2812 Plus Minus Blackboard
コンテスト
ユーザー nu50218
提出日時 2024-07-19 21:38:47
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,494 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,180 ms
コンパイル使用メモリ 367,640 KB
実行使用メモリ 9,224 KB
最終ジャッジ日時 2026-07-08 13:52:51
合計ジャッジ時間 5,447 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef LOCAL
#include <local.hpp>
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2")
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define postprocess(...) ((void)0)
#endif

using namespace std;
using ll = long long;
using ld = long double;

void solve([[maybe_unused]] int test) {
    int N;
    cin >> N;

    vector<ll> positive, negative;
    for (int i = 0; i < N; i++) {
        ll x;
        cin >> x;
        if (x > 0) positive.push_back(x);
        if (x < 0) negative.push_back(x);
    }

    sort(positive.begin(), positive.end());
    sort(negative.begin(), negative.end());

    if (positive.size() + negative.size() <= 1) {
        cout << "Yes" << endl;
        return;
    }
    if (positive.empty()) {
        cout << "No" << endl;
        return;
    }
    if (negative.empty()) {
        cout << "No" << endl;
        return;
    }

    auto sum_positive = accumulate(positive.begin(), positive.end(), 0LL);
    auto sum_negative = accumulate(negative.begin(), negative.end(), 0LL);

    if (sum_positive - positive.back() <= sum_negative) {
        cout << "Yes" << endl;
        return;
    }
    if (sum_negative - negative.back() <= sum_positive) {
        cout << "Yes" << endl;
        return;
    }

    cout << "No" << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }

    postprocess();
}
0