Submission

Status:

[PP][P][P][P][P]

Subtask/Task Score:

{20/20}{20/20}{20/20}{20/20}{20/20}

Score: 100

User: zibozzz_23

Problemset: ติดตั้งหลอดไฟ

Language: cpp

Time: 0.004 second

Submitted On: 2026-08-05 14:22:16

#include <bits/stdc++.h>
using namespace std;

#define ll long long
int pre[1005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    ll ans = 0;
    pre[0] = 0;
    
    for(int i = 0; i < n; ++i){
        if(i == 0){
            pre[i] = pre[i] + a[i];
        }
        
        else{
            pre[i] = pre[i-1] + a[i];
        }
        ans += pre[i] * 2;
    }
    cout << ans << "\n";
}