結果

問題 No.165 四角で囲え!
ユーザー face4face4
提出日時 2019-09-28 10:45:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,961 ms / 5,000 ms
コード長 1,635 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 91,592 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 03:37:58
合計ジャッジ時間 26,335 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 947 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 1,192 ms
6,948 KB
testcase_06 AC 238 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1,075 ms
6,948 KB
testcase_12 AC 1,892 ms
6,948 KB
testcase_13 AC 1,961 ms
6,944 KB
testcase_14 AC 1,436 ms
6,948 KB
testcase_15 AC 1,447 ms
6,944 KB
testcase_16 AC 1,866 ms
6,944 KB
testcase_17 AC 1,836 ms
6,944 KB
testcase_18 AC 1,847 ms
6,944 KB
testcase_19 AC 1,857 ms
6,948 KB
testcase_20 AC 1,854 ms
6,952 KB
testcase_21 AC 1,859 ms
6,944 KB
testcase_22 AC 1,841 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

#define inRange(x,a,b) (a <= x && x <= b)
typedef pair<int,int> pii;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, b;
    cin >> n >> b;
    vector<pair<pii,int>> vp;
    for(int i = 0; i < n; i++){
        int x, y, p;
        cin >> x >> y >> p;
        vp.push_back({{x,y},p});
    }
    sort(vp.begin(), vp.end());
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            int low = vp[i].first.second, high = vp[j].first.second;
            if(low > high)  swap(low, high);
            map<int,int> ms, mv;
            for(int k = 0; k < n; k++){
                if(inRange(vp[k].first.second, low, high)){
                    ms[vp[k].first.first] += (vp[k].second);
                    mv[vp[k].first.first]++;
                }
            }
            vector<int> vs, vv;
            for(auto p : ms)    vs.push_back(p.second);
            for(auto p : mv)    vv.push_back(p.second);
            int l = 0, r = 0, sum = 0, cnt = 0;
            while(l < vs.size()){
                while(r < vs.size() && sum+vs[r] <= b){
                    sum += vs[r];
                    cnt += vv[r];
                    r++;
                }
                ans = max(ans, cnt);
                if(vs[r] > b){
                    l = ++r;
                    sum = 0, cnt = 0;
                    continue;
                }
                sum -= vs[l];
                cnt -= vv[l];
                l++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0