結果

問題 No.165 四角で囲え!
ユーザー motimoti
提出日時 2015-04-15 03:17:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 193 ms / 5,000 ms
コード長 1,128 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 79,860 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 23:42:26
合計ジャッジ時間 3,297 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 127 ms
4,376 KB
testcase_06 AC 27 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 57 ms
4,380 KB
testcase_12 AC 29 ms
4,380 KB
testcase_13 AC 33 ms
4,376 KB
testcase_14 AC 35 ms
4,376 KB
testcase_15 AC 24 ms
4,376 KB
testcase_16 AC 169 ms
4,380 KB
testcase_17 AC 121 ms
4,376 KB
testcase_18 AC 193 ms
4,376 KB
testcase_19 AC 146 ms
4,376 KB
testcase_20 AC 124 ms
4,376 KB
testcase_21 AC 123 ms
4,380 KB
testcase_22 AC 124 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 N; ll B;
map<int, int> MX, MY;
int X[500], Y[500], P[500];
vector<pair<int, int>> D[500];
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;

  int INF = 1e9+1;

  MX[-INF] = MY[-INF] = 0;
  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(x1, MX.size()) REP(x2, x1, MX.size()) {
    int num = 0;
    ll tot = 0;
    y1 = 0;
    rep(y2, MY.size()) {
      for(auto& e: D[y2]) {
        if(e.first >= x1 && e.first <= x2) {
          num ++, tot += e.second;
        }
      }
      while(tot > B) {
        for(auto& e: D[y1]) {
          if(e.first >= x1 && e.first <= x2) {
            num --;
            tot -= e.second;
          }
        }
        y1++;
      }
      ma = max(ma, num);
    }
  }

  cout << ma << endl;

  return 0;
}
0