結果

問題 No.165 四角で囲え!
ユーザー maine_honzukimaine_honzuki
提出日時 2020-06-02 23:59:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 384 ms / 5,000 ms
コード長 1,602 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 185,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 16:42:46
合計ジャッジ時間 5,893 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 240 ms
5,376 KB
testcase_06 AC 48 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 161 ms
5,376 KB
testcase_12 AC 165 ms
5,376 KB
testcase_13 AC 186 ms
5,376 KB
testcase_14 AC 170 ms
5,376 KB
testcase_15 AC 125 ms
5,376 KB
testcase_16 AC 358 ms
5,376 KB
testcase_17 AC 222 ms
5,376 KB
testcase_18 AC 384 ms
5,376 KB
testcase_19 AC 280 ms
5,376 KB
testcase_20 AC 223 ms
5,376 KB
testcase_21 AC 230 ms
5,376 KB
testcase_22 AC 231 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N, B, X[500], Y[500], P[500];
    cin >> N >> B;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> P[i];
    }

    vector<int> V;
    map<int, vector<pair<int, int>>> M;
    for (int i = 0; i < N; i++) {
        V.emplace_back(X[i]);
        M[Y[i]].push_back({X[i], P[i]});
    }
    M[-1000000001] = {};

    sort(V.begin(), V.end());

    int ans = 0;
    for (int i = 0; i < V.size(); i++) {
        for (int j = i; j < V.size(); j++) {
            auto y1 = M.begin();
            auto y2 = M.begin();
            int p = 0;
            int cnt = 0;

            while (y2 != M.end()) {
                if (p < B || y1 == y2) {
                    y2++;
                    if (y2 == M.end())
                        break;
                    for (auto& t : (*y2).second) {
                        if (V[i] <= t.first && t.first <= V[j]) {
                            cnt++;
                            p += t.second;
                        }
                    }
                    if (p <= B)
                        ans = max(ans, cnt);
                } else {
                    for (auto& t : (*y1).second) {
                        if (V[i] <= t.first && t.first <= V[j]) {
                            cnt--;
                            p -= t.second;
                        }
                    }
                    y1++;
                    if (p <= B)
                        ans = max(ans, cnt);
                }
            }
        }
    }

    cout << ans << endl;
}
0