Boj16208_귀찮음

Published: by Creative Commons Licence

boj16208_귀찮음

  • dp 인줄 알았지만 그냥 수학… 알고리즘 틀에 갖쳐있다는걸 느낌…ㅠ
#include<iostream>
#include<algorithm>
using namespace std;

int n;
int arr[500000],sum=0;
long long ans = 0;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
		sum += arr[i];
	}
	for (int i = 0; i < n; i++) {
		ans += ((long long)arr[i]*(sum-arr[i]));
		sum -= arr[i];
	}
	cout << ans;
}