跳到正文

个人记录

P4995 跳跳!

chengcheng_2015约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年2月8日
收录
2026年9月16日
更新
2026年9月16日
篇幅
约 1 分钟

版本

  1. v1当前

P4995 跳跳!

错误原因

没开longlong

代码

C++
#include <bits/stdc++.h>
using namespace std;
int n, a[500];
long long ans;
int main(){
   cin >> n;
   for(int i=1;i<=n;i++)cin >> a[i];
   sort(a,a+n+1);
   int l=0,r=n;
   while(r>l){
       ans+=(a[r]-a[l])*(a[r]-a[l]);
       l++;
       ans+=(a[r]-a[l])*(a[r]-a[l]);
       r--;
   }
   cout << ans;
   return 0;
}
原文