#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
struct node {
int l, r;
} a[N];
int n;
bool cmp(node A, node B) {
if (A.r == B.r)
return A.l > B.l;
return A.r < B.r;
}
int main() {
while (~scanf("%d", &n)) {
if (n == 0)
break;
for (int i = 0; i < n; i ++ )
scanf("%d%d", &a[i].l, &a[i].r);
sort(a, a + n, cmp);
int res = 1; // 先选择观看节目1
for (int i = 1; i < n; i ++ )
if (a[i].l >= a[i - 1].r)
res ++ ;
else
a[i].r = min(a[i].r, a[i - 1].r);
printf("%d\n", res);
}
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int n;
int t[N];
int main() {
int T;
scanf("%d", &T);
while (T -- ) {
scanf("%d", &n);
for (int i = 1; i <= n; i ++ )
scanf("%d", &t[i]);
sort(t + 1, t + 1 + n);
int ans = 0;
while (n) {
if (n == 1) {
ans += t[n];
n = 0;
} else if (n == 2) {
ans += t[n];
n = 0;
} else if (n == 3) {
ans += t[n] + t[1] + t[2];
n = 0;
} else {
if ((t[n] + t[1] + t[n - 1] + t[1]) > (t[2] + t[1] + t[n] + t[2]))
ans += t[2] + t[1] + t[n] + t[2];
else
ans += t[n] + t[1] + t[n - 1] + t[1];
n -= 2;
}
}
printf("%d\n", ans);
}
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 30;
struct node {
int dps, hp;
} p[N];
int n;
bool cmp(node A, node B) {
return A.dps * B.hp > B.dps * A.hp;
}
int main() {
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i ++ )
scanf("%d%d", &p[i].dps, &p[i].hp);
int ans = 0;
sort(p + 1, p + 1 + n, cmp);
for (int i = 1; i <= n; i ++ ) {
while (p[i].hp) {
p[i].hp -- ;
for (int j = i; j <= n; j ++ )
ans += p[j].dps;
}
}
printf("%d\n", ans);
}
return 0;
}