結果

問題 No.165 四角で囲え!
ユーザー pekempeypekempey
提出日時 2015-08-20 16:19:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,577 bytes
コンパイル時間 2,558 ms
コンパイル使用メモリ 152,048 KB
実行使用メモリ 14,736 KB
最終ジャッジ日時 2023-09-25 13:54:42
合計ジャッジ時間 14,593 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

ll N, B;
ll X[400], Y[400], P[400];
ll sum[500][500], num[500][500];

int main() {
	cin >> N >> B;
	rep (i, N) cin >> X[i] >> Y[i] >> P[i];

	vector<ll> xs, ys;
	rep (i, N) {
		xs.push_back(X[i]);
		ys.push_back(Y[i]);
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	ys.erase(unique(ys.begin(), ys.end()), ys.end());

	rep (i, N) {
		X[i] = lower_bound(xs.begin(), xs.end(), X[i]) - xs.begin();
		Y[i] = lower_bound(ys.begin(), ys.end(), Y[i]) - ys.begin();
	}

	int W = xs.size() + 2;
	int H = ys.size() + 2;

	rep (i, N) {
		sum[X[i] + 1][Y[i] + 1] += P[i];
		num[X[i] + 1][Y[i] + 1]++;
	}
	rep (i, W + 1) rep (j, H + 1) {
		sum[i][j + 1] += sum[i][j];
		num[i][j + 1] += num[i][j];
	}
	rep (j, H + 1) rep (i, W + 1) {
		sum[i + 1][j] += sum[i][j];
		num[i + 1][j] += num[i][j];
	}

	ll ans = 0;

	rep (i, W * H) {
		rep2 (j, i, W * H) {
			int x1 = i % W;
			int y1 = i / W;
			int x2 = j % W;
			int y2 = j / W;
			if (x2 <= x1 || y2 <= y1) continue;
			ll total = sum[x2][y2] - sum[x2][y1] - sum[x1][y2] + sum[x1][y1];
			if (total <= B) {
				ll m = num[x2][y2] - num[x2][y1] - num[x1][y2] + num[x1][y1];
				ans = max(ans, m);
			}
		}		
	}
	cout << ans << endl;

	return 0;
}
0