結果

問題 No.165 四角で囲え!
ユーザー motimoti
提出日時 2015-04-15 03:30:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 76,320 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-17 20:24:05
合計ジャッジ時間 3,269 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 126 ms
4,380 KB
testcase_06 AC 27 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 56 ms
4,376 KB
testcase_12 AC 31 ms
4,376 KB
testcase_13 AC 35 ms
4,376 KB
testcase_14 AC 42 ms
4,376 KB
testcase_15 AC 34 ms
4,380 KB
testcase_16 AC 168 ms
4,380 KB
testcase_17 AC 114 ms
4,376 KB
testcase_18 AC 197 ms
4,376 KB
testcase_19 AC 140 ms
4,380 KB
testcase_20 AC 118 ms
4,380 KB
testcase_21 AC 116 ms
4,380 KB
testcase_22 AC 116 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

typedef long long ll;
int const INF = 1<<29;

int N;
ll B;
map<int, int> MX, MY;
int X[555], Y[555], P[555];
vector<pair<int, int>> D[555];

int ma = 0;

int main() {

  cin >> N >> B;
  rep(i, N) {
    cin >> X[i] >> Y[i] >> P[i];
    MX[X[i]] = MY[Y[i]] = 0;
  }

  MX[-INF] = MY[-INF] = MX[INF] = MY[INF] = 0;

  int x1 = 0, y1 = 0;
  for(auto& e: MX) e.second = x1++;
  for(auto& e: MY) e.second = y1++;

  rep(i, N) D[MY[Y[i]]].emplace_back(MX[X[i]], P[i]);

  rep(i, MX.size()) REP(j, i+1, MX.size()) {
    int num = 0;
    ll tot = 0;

    int lower = 0;
    rep(upper, MY.size()) {
      // 上に進む
      for(auto& e: D[upper]) {
        if(i <= e.first && e.first <= j) {
          num ++, tot += e.second;
        }
      }

      // 下を切り落とす
      while(tot > B) {
        for(auto& e: D[lower]) {
          if(i <= e.first && e.first <= j) {
            num --;
            tot -= e.second;
          }
        }
        lower++;
      }
      ma = max(ma, num);
    }
  }

  cout << ma << endl;

  return 0;
}
0