結果

問題 No.165 四角で囲え!
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-13 00:44:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 959 ms / 5,000 ms
コード長 1,390 bytes
コンパイル時間 1,647 ms
コンパイル使用メモリ 155,092 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 23:35:31
合計ジャッジ時間 9,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 291 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 419 ms
4,380 KB
testcase_06 AC 21 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 477 ms
4,380 KB
testcase_12 AC 959 ms
4,380 KB
testcase_13 AC 853 ms
4,380 KB
testcase_14 AC 716 ms
4,380 KB
testcase_15 AC 401 ms
4,376 KB
testcase_16 AC 715 ms
4,376 KB
testcase_17 AC 227 ms
4,380 KB
testcase_18 AC 168 ms
4,376 KB
testcase_19 AC 542 ms
4,380 KB
testcase_20 AC 229 ms
4,380 KB
testcase_21 AC 225 ms
4,380 KB
testcase_22 AC 223 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
  // ios_base::sync_with_stdio(false);
  int N, B;
  cin >> N >> B;

  vector<pair<P, int>> p1, p2;
  rep(i, N) {
    int x, y, p;
    cin >> x >> y >> p;
    p1.push_back(mp(mp(x, y), p));
    p2.push_back(mp(mp(y, x), p));
  }

  sort(all(p1));
  sort(all(p2));

  int ans = 0;
  rep(i, N) REP(j, i, N) {
    int l = p1[i].F.F - 1;
    int r = p1[j].F.F + 1;
    int b = 0;
    vector<pair<P, int>> vp;
    rep(k, N) {
      if(p2[k].F.S <= l || r <= p2[k].F.S) continue;
      int tmp = p2[k].F.F;
      while(k < N && tmp == p2[k].F.F) {
        if(l < p2[k].F.S && p2[k].F.S < r) {
          vp.push_back(p2[k]);
          b += p2[k].S;
        }
        k++;
      }

      if(b > B) {
        while(1) {
          tmp = vp.front().F.F;
          while(vp.size() && tmp == vp.front().F.F) {
            b -= vp.front().S;
            vp.erase(vp.begin());
          }
          if(b <= B) break;
        }
      }

      ans = max(ans, (int)vp.size());
      
      k--;
    }
  }

  cout << ans << endl;
  
  return 0;
}
0