반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- data_structure
- red-black tree
- sort
- c++
- class_template
- 문법
- connected_component
- 13305
- Algorithm
- Biconnected_Component
- qsort
- 구현
- STL
- 백준
- sstream
- '0'
- 예제
- deletion
- Articulation_Point
- Critical_Path_Analysis
- function_template
- singly Linked List
- 5397
- Pair
- 자료구조
- Heap
- 알고리즘
- list
- template
- 총정리
Archives
- Today
- Total
- Today
- Total
- 방명록
어제의 나보다 성장한 오늘의 나
[c++][Greedy] 백준 11399번 문제 풀이 본문
반응형
간단한 Greedy 문제이다.
정렬 후, for 반복으로 arr[i] * (arr_size()-i) 를 다 더해주면 답이 나온다.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int args ,char** argv){
int N;
cin >> N;
vector<int> pi;
int temp;
for(int i = 0 ; i < N ; ++i){
cin >> temp;
pi.push_back(temp);
}
sort(pi.begin() , pi.end());
int pi_size = pi.size();
int answer = 0 ;
for(int i = 0 ; i < N ; ++i){
answer += pi[i] * (pi_size-i);
}
cout << answer;
}
반응형
'c++ > 백준 문제 풀이' 카테고리의 다른 글
[c++][Greedy] 백준 10610번 문제 풀이 (0) | 2022.02.22 |
---|---|
[c++][Greedy] 백준 1789번 문제 풀이 (0) | 2022.02.22 |
[c++][Greedy] 백준 1541번 문제 풀이 (0) | 2022.02.19 |
[c++][Greedy] 백준 13305번 문제 풀이 (0) | 2022.02.19 |
[c++][문제 풀이] 백준 18870번 <좌표 압축> (0) | 2022.02.13 |
Comments