Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:O(n) 0ms~~~~~~

Posted by ncptbtptp at 2014-11-07 08:43:17 on Problem 2231
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator