//Giorgi Kldiashvili
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3020;
struct node
{
int l, r, h, c;
};
bool operator < (node a, node b)
{
return a.r < b.r;
}
int tot, H, n, m;
bool check(node a, node b)
{
if(a.r <= b.l || b.r <= a.l)
return false;
if(a.h + b.h > H)
return true;
return false;
}
vector < node > a, b;
int A[N], B[N];
int dp[N][N];
int answer;
int main()
{
scanf("%d %d", &tot, &H);
a.push_back({0, 0, 0, 0});
b.push_back({0, 0, 0, 0});
while(tot --)
{
int id, l, r, h, cost;
scanf("%d %d %d %d %d", &id, &l, &r, &h, &cost);
if(id == 0)
a.push_back({l, r, h, cost});
else
b.push_back({l, r, h, cost});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
n = a.size() - 1; m = b.size() - 1;
for(int i = 1; i <= n; ++ i)
{
int l = 0; int r = i - 1;
while(l < r)
{
int mid = l + r + 1 >> 1;
if(a[mid].r <= a[i].l)
l = mid;
else
r = mid - 1;
}
A[i] = l;
}
for(int i = 1; i <= m; ++ i)
{
int l = 0; int r = i - 1;
while(l < r)
{
int mid = l + r + 1 >> 1;
if(b[mid].r <= b[i].l)
l = mid;
else
r = mid - 1;
}
B[i] = l;
}
for(int i = 1; i <= m; ++ i)
dp[0][i] = max(dp[0][i - 1], dp[0][B[i]] + b[i].c);
for(int i = 1; i <= n; ++ i)
{
dp[i][0] = max(dp[i - 1][0], dp[A[i]][0] + a[i].c);
for(int j = 1; j <= m; ++ j)
{
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if(check(a[i], b[j]))
{
answer = max(answer, dp[i][j]);
continue;
}
if(a[i].l < b[j].l)
dp[i][j] = max(dp[i][j], dp[i][B[j]] + b[j].c);
else
dp[i][j] = max(dp[i][j], dp[A[i]][j] + a[i].c);
answer = max(answer, dp[i][j]);
}
answer = max(answer, dp[i][0]);
}
printf("%d\n", answer);
}
Compilation message
mat.cpp: In function 'int main()':
mat.cpp:58:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r + 1 >> 1;
~~~~~~^~~
mat.cpp:71:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r + 1 >> 1;
~~~~~~^~~
mat.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &tot, &H);
~~~~~^~~~~~~~~~~~~~~~~~~
mat.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d %d", &id, &l, &r, &h, &cost);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
548 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Incorrect |
3 ms |
616 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12780 KB |
Output is correct |
2 |
Correct |
15 ms |
12780 KB |
Output is correct |
3 |
Correct |
13 ms |
12780 KB |
Output is correct |
4 |
Correct |
18 ms |
12780 KB |
Output is correct |
5 |
Correct |
14 ms |
12784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
15340 KB |
Output is correct |
2 |
Incorrect |
39 ms |
15468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |