結果

問題 No.165 四角で囲え!
ユーザー kosakkunkosakkun
提出日時 2016-12-13 18:24:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,706 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 105,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 02:04:07
合計ジャッジ時間 8,708 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 238 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 314 ms
4,376 KB
testcase_06 AC 64 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 525 ms
4,376 KB
testcase_16 AC 483 ms
4,376 KB
testcase_17 AC 458 ms
4,380 KB
testcase_18 AC 486 ms
4,380 KB
testcase_19 AC 487 ms
4,376 KB
testcase_20 AC 462 ms
4,376 KB
testcase_21 AC 467 ms
4,376 KB
testcase_22 AC 463 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))

ll cntmax(vector< pair<ll,ll> > y, ll cap){
    sort(y.begin(),y.end());
    ll sum=0;
    ll cnt=0;
    ll res=0;
    
    int j=0;
    for(int i=0;i<y.size();i++){
        if(sum+y[i].second<=cap){
            sum+=y[i].second;
            cnt++;
        }else{
            sum-=y[j].second;
            cnt--;
            j++;
            i--;
        }
        res=max(res,cnt);
    }
    
    return res;
}

int main(){
    
    ll N,B; cin>>N>>B;
    vector< pair< pair<ll,ll>,ll > > C(N);
    REP(i,N)cin>>C[i].first.first>>C[i].first.second>>C[i].second;
    
    sort(C.begin(),C.end());
    
    ll ans=0;
    for(int xl=0;xl<N;xl++){
        for(int xr=xl;xr<N;xr++){
            vector< pair<ll,ll> > t;
            for(int i=xl;i<=xr;i++){
                t.push_back(make_pair(C[i].first.second,C[i].second));
            }
            ans=max(ans,cntmax(t,B));
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}
0