結果
| 問題 | No.165 四角で囲え! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-20 16:19:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,577 bytes |
| 記録 | |
| コンパイル時間 | 1,390 ms |
| コンパイル使用メモリ | 165,936 KB |
| 実行使用メモリ | 13,320 KB |
| 最終ジャッジ日時 | 2024-07-18 10:55:48 |
| 合計ジャッジ時間 | 13,901 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 18 |
ソースコード
#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;
}