Codeforces Round 892 (Div. 2) C. Another Permutation Problem
源码:
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
const int maxn = 550;
long long s[maxn];
int main(){
int t;
cin >> t;
while(t--){
long long n;
cin >> n;
long long ans = 0;
s[0] = 0;
for(long long i = 1;i <= n;i++){
s[i] = s[i-1]+i*i;
}
for(long long i = 1;i <= n;i++){
long long sum = s[i-1];
long long maxl = 0;
long long temp;
for(long long j = i;j <= n;j++){
temp = (n-(j-i))*j;
sum += temp;
if(temp>maxl){
maxl = temp;
}
}
sum -= maxl;
if(sum>ans){
ans = sum;
}
}
cout << ans << endl;
}
return 0;
}