#include <iostream>
#include<cstdio>
#include <algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<iomanip>
using namespace std;
int n, p, value1, value2, res = 0, cnt = 1, t=0;
//res表示燃料,cnt表示访问的星球,t表示去了不亏的星球的数量
struct planet {
int get, need;
}a[100005];
bool cmp(planet a, planet b) {
return a.need <= b.need;
}
int main() {
cin >> n >> p;
for (int i = 0; i < n; i++) {
cin >> value1 >> value2;
if (i == p - 1) res += value1;//如果是原始星球
else if (value1 - value2 >= 0) {
a[t].get=value1;
a[t].need = value2;
t++;
//如果这个星球去了不亏就保存在数组a里
}
}
sort(a, a+t, cmp);
for (int i = 0; i < t; i++) {
if (res < a[i].need)break; //如果下一个星球已经去不了了,就退出
res += (a[i].get - a[i].need);//更新燃料
cnt++;//访问数+1
}
cout << res << endl << cnt;
return 0;
}
实在不知道错在哪了,求dalao伸出援手