http://codeforces.com/contest/313/problem/C
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 long long a[3000000]; 6 7 int main() 8 { 9 int n; 10 scanf("%d",&n); 11 for(int i=0; i<n; i++) 12 { 13 scanf("%lld",&a[i]); 14 } 15 sort(a,a+n); 16 long long ans=0,ans1=0; 17 int k=1,j=0; 18 for(int i=n-1; i>=0; i--) 19 { 20 ans1+=a[i]; 21 j++; 22 if(j==k) 23 { 24 ans+=ans1; 25 k=k*4; 26 } 27 } 28 printf("%lld ",ans); 29 return 0; 30 }