QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#589#375854#6823. Coffee OverdosewaretleTx_LcySuccess!2024-04-08 20:49:322024-04-08 20:49:33

Details

Extra Test:

Time Limit Exceeded

input:

100000
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
172800 1
17280...

output:

14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
14930006400
...

result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375854#6823. Coffee OverdoseTx_LcyTL 433ms4028kbC++14806b2024-04-03 16:32:382024-04-08 20:50:04

answer

//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
int S,C,ans1,ans2;
inline void solve(){
	cin>>S>>C,ans1=ans2=0;
	int wz=(S+C)/(C+1);
	{
		ans1=C*(S+S-(C+1)*(wz-1))*wz/2;
		//一开始就喝咖啡
	}
	{
		rep(k,0,S/C)
			ans2=max(ans2,C*(C-1)/2*k-C*(k-1)*k/2+(S+1)*S/2);
		//一开始没喝咖啡
	}
	cout<<max(ans1,ans2)<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t=1;
	cin>>t;
	while (t--) solve();
	cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<" s\n";
	return 0;
}