#include<bits/stdc++.h>usingnamespace std;#defineIOSios::sync_with_stdio(0),cin.tie(0),cout.tie(0)#defineendl"\n"#defineintlonglong#definerepn(i,a,n)for(int i = a; i <= n; i++)#definerep(i,a,n)for(int i = a; i < n; i++)typedef pair<int,int> PII;constint N =1e6+10;int a[N],b[N];voidsolve(){int n,k,ans=1e15,minn=1e15,res=0;
cin>>n>>k;repn(i,1,n) cin>>a[i];repn(i,1,n) cin>>b[i],b[i]+=a[i];//答案一定在取前i个元素,剩下的取k-i个前i个元素中的b的最小值 repn(i,1,min(k,n)){
res+=a[i];
minn=min(minn,b[i]);//每次保存前面的最小值
ans=min(ans,res+(k-i)*minn);//取前i个元素a1~an,剩下的k-i次取最小值 // cout<<minn<<' '<<res<<' '<<ans<<endl;}
cout<<ans<<endl;}signedmain(){// IOS;int T=1;// cin>>T;while(T--){solve();}return0;}
D.蓝桥快打
基本思路
找出多方需要多少次打败自己,记住要向上取整,这里用来向上取整函数ceil();
代码
#include<bits/stdc++.h>usingnamespace std;#defineIOSios::sync_with_stdio(0),cin.tie(0),cout.tie(0)#defineendl"\n"#defineintlonglong#definerepn(i,a,n)for(int i = a; i <= n; i++)#definerep(i,a,n)for(int i = a; i < n; i++)typedef pair<int,int> PII;constint N =1e5+10;int a,b,c;voidsolve(){
cin>>a>>b>>c;int k=ceil(1.0*a/c);//对方需要多少次打败自己 int res=ceil(1.0*b/k);//自己以最小的攻击力打对方多少次能打败对面
cout<<res<<endl;}signedmain(){// IOS;int T=1;
cin>>T;while(T--){solve();}return0;}