結果

問題 No.165 四角で囲え!
コンテスト
ユーザー moti
提出日時 2015-04-12 19:36:11
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,141 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,273 ms
コンパイル使用メモリ 191,504 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-25 22:00:36
合計ジャッジ時間 2,845 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

#define chmax(a,x) a = max(a, x)

typedef long long ll;

ll N, B;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> pi3;
vector<pi3> p;

int main() {

  set<int> xset;
  cin >> N >> B;
  rep(i, N) {
    ll x, y, sc; cin >> x >> y >> sc;
    p.emplace_back(pii{x, y}, sc);
  }

  ll ans = 0;
  
  rep(_, 2) {

  vector<int> xs;
  rep(i, N) xset.insert(p[i].first.first);
  for(auto e: xset) { xs.push_back(e); }

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

  rep(I, xs.size()) REP(J, I, xs.size()) {
    int i = lower_bound(p.begin(), p.end(), pi3{pii{xs[I], -1e9-1},0})-p.begin();
    int j = lower_bound(p.begin(), p.end(), pi3{pii{xs[J],  1e9+1},0})-p.begin()-1;
    int L = i, R = i;
    ll sum = 0;
    while(L <= j && R <= j) {
      if(sum + p[R].second <= B) {
        sum += p[R++].second;
        chmax(ans, (ll)(R-L));
      }
      else {
        sum -= p[L++].second;
        if(sum < 0) { R = L; sum = 0; }
      }
    }
  }

  rep(i, N) swap(p[i].first.first, p[i].first.second);
  }

  cout << ans << endl;

  return 0;
}
0