mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 14:18:47 +00:00
P1868 饥饿的奶牛
R73067558
This commit is contained in:
parent
a4a780f56e
commit
c0d0f81ff3
39
Luogu/P1868/P1868.cpp
Normal file
39
Luogu/P1868/P1868.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1.5e5 + 5,
|
||||
M = 3e6 + 5;
|
||||
|
||||
int n, f[M], e[M];
|
||||
int l = std::numeric_limits<int>::max(),
|
||||
r = std::numeric_limits<int>::min();
|
||||
std::pair<int, int> a[N];
|
||||
bool vis[M];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n;
|
||||
for (int i = 1, x, y; i <= n; i++) {
|
||||
cin >> x >> y;
|
||||
r = std::max(r, y);
|
||||
e[x] = y;
|
||||
vis[x] = true;
|
||||
}
|
||||
|
||||
for (int i = r; i; i--) {
|
||||
if (vis[i]) {
|
||||
f[i] = std::max(f[i + 1], f[e[i] + 1] + (e[i] - i + 1));
|
||||
} else {
|
||||
f[i] = f[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
cout << f[1] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user