先依次合并小的
两个数组,一个放合并前的
一个放合并后的值,
依次去判断两个数组,找最小值
a b
a先b 后 :a
b先 a 后 : b
时间小的在前面
最短时间 : 某一个,min(a[i] , l+1-a[i])
max(res[i])
最长时间: 某一个人 max(a[i] , l+1-a[i])
max(res[i])
//开始时间,结束时间,持续时间
//
//优先选择结束时间最早的
//[a,10] 10 11 12
//[a,12] 12 13 14
//决策包容性, a 的选择后续的可能包含了
//b 选择后续的可能,a 有 b 没有的,
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, cnt;
struct node {
int l, r;
bool operator <(const node a)const {
return r < a.r;
}
};
node a[N];
int main() {
freopen("huodong.in", "r", stdin);
freopen("huodong.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].l >> a[i].r;
sort(a + 1, a + 1 + n);
cnt = 1;
int last = a[1].r;
for (int i = 2; i <= n; i++)
if (a[i].l >= last)
cnt++, last = a[i].r;
cout << cnt;
return 0;
}
// 优先选择单位价值比最高的
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int n, m;
struct node {
int w, v;
double ave;
bool operator <(const node a) {
return ave > a.ave;
}
};
node a[N];
double ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i].w >> a[i].v;
a[i].ave = a[i].v * 1.0 / a[i].w;
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n && m; i++) {
if (m >= a[i].w)
ans += a[i].v, m -= a[i].w;
else
ans += a[i].ave * m, m = 0;
}
printf("%.2lf", ans);
return 0;
}