GitHubSeob
C++ / 백준 / 11399 / ATM 본문
문제
https://www.acmicpc.net/problem/11399
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
문제풀이
돈을 뽑는 시간 + 누적 시간을 계속해서 더하면 된다.
시간이 적게 걸리는 순으로 정렬을 한 뒤 시간을 누적시키기만 하면 된다.
코드
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N = 0;
int idx = 0;
int acc = 0;
int answer = 0;
cin >> N;
vector<int>time(N, 0);
for (idx = 0; idx < N; ++idx)
cin >> time[idx];
sort(time.begin(), time.end());
for (idx = 0; idx < N; ++idx) {
acc += time[idx];
answer += acc;
}
cout << answer;
}
'Baekjoon > Silver' 카테고리의 다른 글
C++ / 백준 / 10819 / 차이를 최대로 (0) | 2021.09.09 |
---|---|
C++ / 백준 / 1476 / 날짜 계산 (0) | 2021.09.08 |
C++ / 백준 / 1931 / 회의실 배정 (0) | 2021.09.05 |
C++ / 백준 / 1783 / 병든 나이트 (0) | 2021.09.05 |
C++ / 백준 / 10610 / 30 (0) | 2021.09.02 |