11.Greedy 알고리즘 - C++
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX 1001
int main() {
int N;
scanf("%d", &N);
vector<int> P(N);
for(int i = 0; i < N; i++) {
scanf("%d", &P[i]);
}
sort(begin(P), end(P));
int target = 0;
for(int i = 0; i < N; i++) {
target += P[i] * (N - i);
}
printf("%d", target);
return 0;
}
// 백준 https://www.acmicpc.net/problem/11399
//5
//3 1 4 3 2
Leave a comment