补题 abc353 c题 思维 + 双指针
作者:
多米尼克領主的致意
,
2024-05-12 21:55:36
,
所有人可见
,
阅读 3
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, mod = 1e8;
typedef long long ll;
int n;
ll ans;
int a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
ans += (ll)a[i] * (n - 1);
}
sort(a + 1, a + 1 + n);
ll cnt = 0;
for(int i = 1, j = n;i <= n;i++){
while(a[i] + a[j] >= mod && j > i)j--;
cnt += n - j;
j = max(j, i + 1);
}
ans -= cnt * mod;
cout << ans;
return 0;
}