結果
問題 |
No.165 四角で囲え!
|
ユーザー |
![]() |
提出日時 | 2015-10-22 22:56:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,712 bytes |
コンパイル時間 | 1,705 ms |
コンパイル使用メモリ | 166,648 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 23:00:12 |
合計ジャッジ時間 | 5,175 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 WA * 11 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i, n) for(int i=0; i<(n); i++) #define ALL(a) (a).begin(),(a).end() struct P { int x, y, p; P(){}; P(int _x, int _y): x(_x), y(_y){}; }; int N,T,B; vector<P> ps; bool comp(int i, int j) { return ps[i].y < ps[j].y; } signed main() { cin >> N >> B; ps.resize(N); REP(i,N) cin >> ps[i].x >> ps[i].y >> ps[i].p; vector<int> ys; REP(i,N) ys.push_back(i); sort(ALL(ys), comp); int maxn = 0; REP(i,N) REP(j,i) { int x0 = min(ps[i].x, ps[j].x); int x1 = max(ps[i].x, ps[j].x); int bottom = 0; int top = -1; int point = 0; int num = 0; // 尺取り法 while(top < N) { if (top == -1) { P p = ps[ys[bottom]]; if (p.x < x0 || x1 < p.x) { bottom++; continue; } top = bottom; } P p = ps[ys[top]]; if (p.x < x0 || x1 < p.x) { top++; continue; } num++; point += p.p; while(top + 1 < N && ps[ys[top+1]].y == ps[ys[top]].y) { top++; P p = ps[ys[top]]; if (p.x < x0 || x1 < p.x) { continue; } point += p.p; num++; } while (point > B) { point -= ps[ys[bottom]].p; num--; bottom++; } maxn = max(maxn, num); // 次へ top++; } } cout << maxn << endl; return 0; }