結果
問題 | No.165 四角で囲え! |
ユーザー |
![]() |
提出日時 | 2015-03-13 00:02:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 518 ms / 5,000 ms |
コード長 | 1,834 bytes |
コンパイル時間 | 1,287 ms |
コンパイル使用メモリ | 97,232 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-26 03:15:21 |
合計ジャッジ時間 | 7,938 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <numeric> #include <cctype> #include <tuple> #include <array> #include <climits> #include <bitset> #include <cassert> #include <unordered_map> #ifdef _MSC_VER #include <agents.h> #endif #define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define REV(v) v.rbegin(), v.rend() #define MEMSET(v, s) memset(v, s, sizeof(v)) #define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end()) #define MP make_pair #define MT make_tuple using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); int n, b; cin >> n >> b; vector<int> x(n), y(n), p(n); vector<tuple<int, int, int>> v(n); rep(i, n) cin >> x[i] >> y[i] >> p[i]; rep(i, n) v[i] = MT(x[i], y[i], p[i]); sort(ALL(v)); rep(i, n){ tie(x[i], y[i], p[i]) = v[i]; } int ans = 0; rep(i, n) rep(j, n){ int y1 = y[i], y2 = y[j]; if (y1 > y2) continue; int l = 0, r = 0; int sum = 0, cnt = 0; int lastl = -1, lastr = -1; while (1){ while (r < n && sum <= b){ if (sum <= b) ans = max(ans, cnt); lastr = r; while (r < n && x[lastr] == x[r]){ if (y1 <= y[r] && y[r] <= y2){ ++cnt; sum += p[r]; } ++r; } } if (sum <= b) ans = max(ans, cnt); if (l >= r) break; lastl = l; while (l < n && x[lastl] == x[l]){ if (y1 <= y[l] && y[l] <= y2){ --cnt; sum -= p[l]; } ++l; } if (sum <= b) ans = max(ans, cnt); } } cout << ans << endl; }