Koala - 14기/코딩테스트 준비 스터디

백준 30088번 공포의 면담실 C++

Kim Doo Hyeon 2024. 4. 8. 00:10

문제

 

https://www.acmicpc.net/problem/30088


Algorithm

각 부서별로 면담 시간의 합이 적은 순서대로 정렬한 뒤, 누적합을 구하여 출력한다.

 


 

 

Code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define IAMFAST ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

ll n;
vector<ll> v;

void INPUT()
{
    IAMFAST
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int num; cin >> num;
        ll sum = 0;
        while (num--)
        {
            ll t; cin >> t;
            sum += t;
        }
        v.emplace_back(sum);
    }
}

void solution()
{
    sort(v.begin(), v.end());

    ll ans = 0;
    for (int i = 0; i< n; i++)
        ans += v[i] * (n - i);
    cout << ans;
}

int main()
{
    INPUT();
    solution();
}