Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 11399번 - ATM 본문
sort를 잘 사용하면 되는 문제
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> v;
v.resize(n);
int total = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j <= i; j++) {
total += v[j];
}
}
cout << total << "\n";
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 1620 - 나는야 포켓몬 마스터 이다솜 (0) | 2021.08.17 |
|---|---|
| [C++] 백준 11659 - 구간 합 구하기 4 (0) | 2021.08.16 |
| [C++] 백준 1463번 - 1로 만들기 (0) | 2021.08.16 |
| [C++] 백준 17219번 - 비밀번호 찾기 (0) | 2021.08.16 |
| [C++] 백준 11723번 - 집합 (0) | 2021.08.14 |
Comments