「杂题乱刷」AT_abc253_c

感觉要好好补补 set 了。

链接

直接用 set 模拟即可。

点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define forll(i,a,b,c) for(register long long i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(register long long i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
ll t;
ll n,sum,mi;
struct node{
	ll x,y;
}a[200010];
bool cmp(node x,node y){
	return x.x>y.x;
}
void solve()
{
	sum=0,mi=0;
	cin>>n;
	forl(i,1,n)
		cin>>a[i].x;
	forl(i,1,n)
		cin>>a[i].y,mi+=a[i].y;
	sort(a+1,a+1+n,cmp);
	forl(i,1,n)
	{
		sum+=a[i].y;
		if(sum>a[i].x)
		{
			sum-=a[i].y;
			cout<<min({max(sum,a[i].x),mi,a[1].x})<<endl;
			return ;
		}
	}
	cout<<min(mi,a[1].x)<<endl;
}
/*
4
4
3 7 4 5
2 1 2 4
4
1 2 3 4
3 3 3 3
2
1 2
10 10
2
10 10
1 2
*/
int main()
{
	IOS;
	t=1;
	cin>>t;
	while(t--)
		solve();
    /******************/
	/*while(L<q[i].l) */
	/*    del(a[L++]);*/
	/*while(L>q[i].l) */
	/*    add(a[--L]);*/
	/*while(R<q[i].r) */
	/*	  add(a[++R]);*/
	/*while(R>q[i].r) */
	/*    del(a[R--]);*/
    /******************/
	QwQ;
}
posted @ 2024-04-22 21:16  wangmarui  阅读(2)  评论(0编辑  收藏  举报