이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N, W, ans;
struct cor{
	int x, i;
	bool r;
	cor(int i_, int x_, bool r_){
		i = i_, x = x_;
		r = r_;
	}
	bool operator < (const cor &other) const{
		return x < other.x;
	}
};
struct MAT{
	int P, L, R, H, K;
	MAT(int P_, int L_, int R_, int H_, int K_){
		P = P_, L = L_, R = R_, H = H_, K = K_;
	}
	bool meet(const MAT &MT) const{
		if (R <= MT.L || L >= MT.R) return false;
		return P == MT.P ? true : ((MT.H) + H) > W;
	}
	bool operator < (const MAT &MT) const{
		return R != MT.R ? R < MT.R : L < MT.L;
	}
};
vector<MAT> A;
vector<cor> B;
int D[3001][6001], Left[3001];
bool M[3001][3001];
void input(){
	cin >> N >> W;
	int P, L, R, H, K;
	for (int i=0; i<N; i++){
		cin >> P >> L >> R >> H >> K;
		A.push_back(MAT(P, L, R, H, K));
	}
}
void init(){
	sort(A.begin(), A.end());
	for (int i=0; i<N; i++){
		B.push_back(cor(i, A[i].L, false));
		B.push_back(cor(i, A[i].R, true));
	}
	sort(B.begin(), B.end());
	for (int i=0; i<N; i++){
		M[i][i] = true;
		for (int j=0; j<N; j++){
			if (A[i].meet(A[j])) M[i][j] = true, M[j][i] = true;
			for (int j=0; j<2*N; j++){
				if (B[j].i == i){
					if (!B[j].r) Left[i] = j;
				}
			}
		}
	}
}
void solve(){
	for (int i=0; i<N; i++){
		for (int j=0; j<2*N; j++){
			if (A[i].R < B[j].x) break;
			D[i][j] = A[i].K;
			if (j > 0) D[i][j] = max(D[i][j], D[i][j-1]);
			if (B[j].r){
				int k = B[j].i;
				if (A[k].R <= A[i].L){
					D[i][j] = max(D[i][j], D[k][j] + A[i].K);
				}
				else if (!M[i][k]){
					if (A[k].L < A[i].L){
						D[i][j] = max(D[i][j], D[k][Left[i]] + A[i].K);
					}
					else{
						D[i][j] = max(D[i][j], D[i][Left[k]] + A[k].K);
					}
				}
			}
			ans = max(ans, D[i][j]);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	input();
	init();
	solve();
	cout << ans << endl;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |