結果

問題 No.165 四角で囲え!
ユーザー togatogatogatoga
提出日時 2015-04-06 08:00:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 925 ms / 5,000 ms
コード長 1,680 bytes
コンパイル時間 1,369 ms
コンパイル使用メモリ 149,840 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 23:41:25
合計ジャッジ時間 13,109 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 464 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 579 ms
4,376 KB
testcase_06 AC 105 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 384 ms
4,380 KB
testcase_12 AC 303 ms
4,380 KB
testcase_13 AC 275 ms
4,380 KB
testcase_14 AC 916 ms
4,380 KB
testcase_15 AC 886 ms
4,376 KB
testcase_16 AC 925 ms
4,380 KB
testcase_17 AC 877 ms
4,380 KB
testcase_18 AC 804 ms
4,380 KB
testcase_19 AC 906 ms
4,376 KB
testcase_20 AC 907 ms
4,376 KB
testcase_21 AC 904 ms
4,376 KB
testcase_22 AC 884 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long, long> pll;

const int INF = 1 << 29;
const double EPS = 1e-9;
const int MOD = 100000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
class Data {
public:
  int x, y, p;
  bool operator<(const Data &d) const {
    if (x == d.x){
      return y < d.y;
    }else{
    return x < d.x;
    }

  }
};
int main() {
  int n, b;
  cin >> n >> b;
  vector<Data> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i].x >> d[i].y >> d[i].p;
  }
  sort(d.begin(), d.end());
  int ans = 0;
  for (int s = 0; s < n; s++) {
    for (int t = 0; t < n; t++) {
      int y1 = d[s].y;
      int y2 = d[t].y;
      int l = 0, r = 0;
      int sum = 0;
      int cnt = 0;
      int lastl,lastr;
      lastl = lastr = -1;
      while (1){
        while (r < n && sum <= b){
          if (sum <= b){
            ans = max(ans, cnt);
          }
          lastr = r;
          while (r < n&& d[lastr].x == d[r].x){
            if (y1 <= d[r].y && d[r].y <= y2){
              cnt++;
              sum += d[r].p;
            }
            r++;
          }
        }
        if (sum <= b)ans = max(ans, cnt);
        if (l >= r)break;
        lastl = l;
        while (l < n && d[lastl].x == d[l].x) {
          if (y1 <= d[l].y && d[l].y <= y2){
            cnt--;
            sum -= d[l].p;
          }
          l++;
        }
        if (sum <= b)ans = max(ans, cnt);
      }
      }
    }
    cout << ans << endl;

  return 0;
}
0