![[백준 C++] 1927 : 최소 힙](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FtLr1t%2FbtsLjL38bXu%2FLzGwUxeKfi5KeHlPgyIht1%2Fimg.png)
https://www.acmicpc.net/problem/1927#include #include #include #include using namespace std;int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int N; int input; priority_queue, greater> pq; cin >> N; for (int i = 0; i > input; if (input == 0) { if (!pq.empty()) { cout 우선순위 큐는 기본적으로 내림차순이기 때문에 greater를 사용하여 오름차순으로 변경해주었다.endl을 사용할 시 항상 버퍼를 비우는 작업 때문에 시간초과가 발생할 수 있으므로 '\n..
![[백준 C++] 11659 : 구간 합 구하기 4](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FceIKMB%2FbtsK7FXOlMm%2FUnuqL6yCR1hnaOq6gRNc8K%2Fimg.png)
https://www.acmicpc.net/problem/11659간단해보이는 문제지만, 그냥 생각나는 대로 이중 for문을 사용하면 시간초과가 발생하는 문제이다.#include #include using namespace std;int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int N, M; cin >> N >> M; vector list = vector(N, 0); vector prefix = vector(N, 0); vector ans; for (int i = 0; i > list[i]; prefix[0] = list[0]; for (int i = 1; i > start >> end; if (start - 2 >= 0) ..
![[백준 C++] 11399 : ATM](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbHhHUv%2FbtsK66UDDWP%2FfCelJkZjBKaF2aES90ZWl1%2Fimg.png)
https://www.acmicpc.net/problem/11399그리디 알고리즘을 이용한 문제이다.#include #include #include using namespace std;int main(){ int N, ans = 0; cin >> N; vector list = vector(N, 0); for (int i = 0; i > list.at(i); sort(list.begin(), list.end()); for (int i = 0; i 문제에 적혀있는데로 P1 = 3, P2 = 1, P3 = 4, P4 = 3, P5 = 2 인 경우일 때, [1, 2, 3, 4, 5] 순서이면 다음과 같이 시간이 소요된다. 즉, 처음 시작하는 사람의 소요시간 * N 으로 시작하여 N이 1까지 줄어들면 총 합을 구..
![[백준 C++] 11723 : 집합](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Feh6eK2%2FbtsK58xTXpO%2FYTKUChQ4yTjh7Qzlrkvlb1%2Fimg.png)
https://www.acmicpc.net/problem/11723시간초과에 주의하여 풀면 되는 간단한 문제이다.#include #include using namespace std;int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); set list; int M; cin >> M; for (int m = 0; m > str; if (str.compare("add") == 0) { int input; cin >> input; list.insert(input); } else if (str.compare("remove") == 0) { int input; cin >> input; list.erase(input);..
![[백준 C++] 1874 : 스택 수열](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbPX0gr%2FbtsK3fFgps4%2FaosM6sVxXokkmG4OGA7JjK%2Fimg.png)
https://www.acmicpc.net/problem/1874문제의 설명을 바로 이해하지 못했는데 간단하게 말하면 다음과 같다.1부터 입력된 N까지 수를 스택에 넣을건데, 2번째 줄부터 입력된 수부터 차례대로 POP해서 스택에 모든 값들이 빠지는 지 확인하는 것이다.#include #include #include using namespace std;int main(){ vector ans; stack stack; int N; int value = 1; bool clear = true; cin >> N; for (int i = 0; i > input; while (value 어차피 NO가 뜰 경우는 입력된 수가 이전에 들어가서 스택의 TOP값이 입력값보다 높은 경우밖에 없다.그러므로 입력을 하나씩..
![[백준 C++] 18110 : solved.ac](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FGUR4J%2FbtsK1XY2FIh%2FCrHo7LQ53oGXWlurUUthc1%2Fimg.png)
https://www.acmicpc.net/problem/18110위 아래 각각 15%제외한 나머지 값의 평균을 구하는 문제이다.모든 값에 반올림이 필요한데, c++의 경우 11버전 이상이기만 하면 round함수로 간단하게 반올림을 진행할 수 있다.#include #include #include #include using namespace std;int main(){ int N; int ans = 0; double sum = 0; vector list; cin >> N; if (N != 0) { for (int i = 0; i > temp; list.push_back(temp); } sort(list.begin(), list.end()); int exception = round(N * 0.15..