【题目链接】:http://codeforces.com/contest/810/problem/B
【题意】
每天有ki件物品,你知道每天能卖掉li件;
然后让你选f天;
这f天,可以将ki乘上2;
每天结束之后物品清空;
问你最多能卖多少件物品;
【题解】
先算出来不用f天的乘2效果;
卖出的物品数目;
然后考虑;
乘2之后,能够多卖的物品数量;
排个序,逆序排,然后取前f个就好;
累加答案;
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100;
int n,f;
LL k[N],l[N];
LL b[N];
LL ans = 0;
int main()
{
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> f;
rep1(i,1,n)
cin >> k[i] >> l[i];
rep1(i,1,n)
ans+=min(k[i],l[i]);
rep1(i,1,n)
{
if (k[i]<l[i])
{
l[i]-=k[i];
b[i] = min(k[i],l[i]);
}
else
{//k[i]>=l[i];
b[i] = 0;
}
}
sort(b+1,b+1+n);
reverse(b+1,b+1+n);
rep1(i,1,f)
ans+=b[i];
cout << ans << endl;
return 0;
}