Dishonest Sellers
time limit per test 2 second memory limit per test 256 megabytes
Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.

Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.

Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.

传送门:CF779C

Input

In the first line there are two positive integer numbers n and k (1≤n≤2·105, 0≤k≤n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1,a2,...,an (1≤ai≤104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1,b2,...,bn (1≤bi≤104) — prices of items after discounts (i.e. after a week).

Output

Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.

Sample Input

1
2
3
3 1
5 4 6
3 1 5

Sample Output

1
10

题解

简单贪心 降价减去未降价的,从大到小排 cf结算时RE了,很尴尬,发现了一个从未注意过的Java比较器的问题,另一篇文章会讲
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.*;  
import java.util.*;
public class Main {

public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
while(sc.hasNext()){
int n=sc.nextInt();
int k=sc.nextInt();
int[]a=new int[n];
int[]b=new int[n];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
for(int i=0;i<n;i++)b[i]=sc.nextInt();
Item[]dif=new Item[n];
for(int i=0;i<n;i++)dif[i]=new Item(b[i]-a[i],i,a[i],b[i]);
Arrays.sort(dif,new Comparator<Item>(){
public int compare(Item a, Item b) {
if(a.dif>b.dif) return -1;
if(a.dif<b.dif) return 1;
return 0;
}

});
int count=0;
int sum=0;
for(int i=0;i<n;i++){
if(count<k){
sum+=dif[i].a;
count++;
}
else{
if(dif[i].dif>0){
sum+=dif[i].a;
}
else sum+=dif[i].b;
}
}
pw.println(sum);
pw.flush();
}

}

}
class Item{
int dif;
int index;
int a;
int b;
Item(int dif,int i,int a,int b){
this.dif=dif;
this.index=i;
this.a=a;
this.b=b;
}
}