「codechefTADELIVE」Delivery Man
假设先都给x,然后再贪心选取一些给y
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 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<map> #define N 1000005 #define inf 1000000000 #define ll long long using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,x,y,ans; struct data{ int x,y; }a[100005]; bool operator<(data a,data b) { return a.y-a.x>b.y-b.x; } int main() { n=read();x=read();y=read(); for(int i=1;i<=n;i++) { a[i].x=read(); ans+=a[i].x; } for(int i=1;i<=n;i++)a[i].y=read(); sort(a+1,a+n+1); int t=n-x; for(int i=1;i<=y;i++) if(a[i].y-a[i].x>0||i<=t)ans+=a[i].y-a[i].x; else break; printf("%d\n",ans); return 0; } |
Subscribe