QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#417819#1864. Might and MagicKevin5307RE 0ms0kbC++231.5kb2024-05-22 22:39:372024-05-22 22:39:38

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 22:39:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-22 22:39:37]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int Cp,Cm,H0,A1,D1,N;
		cin>>Cp>>Cm>>H0>>A1>>D1>>N;
		vector<int> vec;
		for(int i=1;i<=2||(i-2)*(i-2)<=H0;i++)
		{
			vec.pb(i);
			vec.pb((H0+i-1)/i);
		}
		srt(vec);
		ll ans=0;
		for(auto x:vec)
		{
			ll lim=(x==1?1ll*inf*inf:(H0-1)/(x-1));
			while((H0+lim-1)/lim<x)
				lim--;
			ll lim2=lim/Cp;
			if(lim2<=0) continue;
			ll limD=max(0ll,A1-lim2);
			if(limD>N) continue;
			ll cur=N-limD;
			ans=max(ans,1ll*Cp*x*max(1ll,cur-D1));
			if(x<=cur)
				ans=max(ans,1ll*Cm*x*(cur-x));
			ll mid=(cur-Cp/Cm)/2;
			for(int a=max(0ll,mid-5);a<=min({cur,(ll)x,mid+5});a++)
				ans=max(ans,1ll*Cm*(cur-a)*a+1ll*Cp*(x-a));
		}
		cout<<ans<<endl;
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

2
1 1 4 5 1 4
2 5 1 9 9 6

output:

4

result: