| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:O(n) 0ms~~~~~~In Reply To:O(n) 0ms~~~~~~ Posted by:root123 at 2013-03-08 12:28:21 > #include <cstdio>
> #include <algorithm>
> using namespace std;
> int a[10004];
> int main() {
> int i, j, n;
> scanf("%d", &n);
> __int64 ans = 0, tp = 0;
> for(i = 1; i <= n; i++) scanf("%d", &a[i]);
> sort(a+1, a+n+1);
> for(i = 1; i < n; i++)
> ans += (__int64)i*(n-i)*(a[i+1]-a[i]);
> printf("%I64d\n", ans<<1);
> return 0;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator