반응형
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 |
Tags
- 13305
- 알고리즘
- 예제
- 총정리
- data_structure
- 백준
- class_template
- STL
- Articulation_Point
- 5397
- deletion
- '0'
- connected_component
- qsort
- red-black tree
- c++
- Pair
- Critical_Path_Analysis
- function_template
- Biconnected_Component
- list
- 구현
- 자료구조
- singly Linked List
- Heap
- sstream
- Algorithm
- sort
- 문법
- 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