NC243733. Coffee Overdose
描述
输入描述
见 PDF 题面
输出描述
见 PDF 题面
示例1
输入:
4 1 2 2 1 10 4 172800 172800
输出:
2 3 63 29859840000
C++(g++ 7.5.0) 解法, 执行用时: 51ms, 内存消耗: 1584K, 提交时间: 2022-10-20 17:25:19
#include <bits/stdc++.h> using namespace std; int t; long long s,c,k,ans; int main() { scanf("%d",&t); for (int o=1;o<=t;++o) { scanf("%lld%lld",&s,&c); if(c>s) { printf("%lld\n",c*s); } else { k=min(c/2,(s+1)/c); ans=((c-k)*c*k+s*(s+1))/2; k=(s-1)/(c+1)+1; ans=max(ans,c*k*s-k*(k-1)*c*(c+1)/2); printf("%lld\n",ans); } } return 0; }
C++(clang++ 11.0.1) 解法, 执行用时: 50ms, 内存消耗: 1628K, 提交时间: 2022-09-26 22:40:29
#include <bits/stdc++.h> using namespace std; int T,s,c; long long calc(int x){ if (x<=0) return -1; int k=(x+c)/(c+1)-1; return (1ll*(s+x+1)*(s-x)+(2ll*x*c-1ll*k*(c+1)*c)*(k+1))/2; } void Main(){ scanf("%d%d",&s,&c); int u=min(1ll*(c+1)*c/2,1ll*s); int x=u/c*c; printf("%lld\n",max(calc(x),max(calc(u),1ll*s*(s+1)/2))); } int main(){ for (scanf("%d",&T);T--;Main()); return 0; }