CF 420 821B Okabe and Banana Trees

題解:
這道題我看的是別人的解釋,
https://www.cnblogs.com/shingen/p/7105280.html

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
int main()
{
    LL m,b;
    while(~scanf("%lld%lld",&m,&b))
    {
        LL sum=0,ans=0;
        for(int y=0;y<=b;y++)
        {
            LL x=(b-y)*m;
            LL sum= x*(1+x)/2*(1+y)+y*(1+y)/2*(1+x);
            //等差數列求和公式推導 
            ans=max(sum,ans);
        }
        printf("%lld\n",ans);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章