結果

問題 No.165 四角で囲え!
ユーザー 沙耶花
提出日時 2021-11-03 12:24:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 1,032 bytes
コンパイル時間 3,816 ms
コンパイル使用メモリ 206,732 KB
最終ジャッジ日時 2025-01-25 10:52:32
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 5000000000000000000



int main(){	
	
	int N,B;
	cin>>N>>B;
	
	vector<int> x(N),y(N),p(N);
	vector<int> t;
	vector<int> ind;
	rep(i,N){
		cin>>x[i]>>y[i]>>p[i];
		t.push_back(x[i]);
		ind.push_back(i);
	}
	sort(ind.begin(),ind.end(),[&](int a,int b){
		return y[a]<y[b];
	});
	
	
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	int ans = 0;
	rep(i,t.size()){
		for(int j=i;j<t.size();j++){
			
			vector<pair<int,int>> temp;
			rep(k,N){
				if(x[ind[k]]>=t[i]&&x[ind[k]]<=t[j]){
					temp.emplace_back(y[ind[k]],p[ind[k]]);
				}
			}
			int s = 0,l = 0;
			rep(k,temp.size()){
				s += temp[k].second;
				if(k!=temp.size()-1 && temp[k+1].first==temp[k].first)continue;
				while(true){
					if(s<=B){
						if(l==0 || temp[l].first!=temp[l-1].first)break;
					}
					s -= temp[l].second;
					l++;
				}
				ans = max(ans,k-l+1);
			}
			
		}
	}
	cout<<ans<<endl;
	
	return 0;
	
}
0