백준 10025번
·
Study/Algorithm
https://www.acmicpc.net/problem/10025 10025번: 게으른 백곰 첫 줄에 정수 N과 K가 들어온다. 둘째 줄부터 N째 줄까지, 공백을 사이에 두고 각 양동이의 얼음의 양을 나타내는 gi와 양동이의 좌표를 나타내는 xi가 주어진다. www.acmicpc.net #include #include using namespace std; int n, k, a[1000001], s, ans; int main() { cin >> n >> k; int b, c; for (int i = 0; i > b >> c; a[c] = b; } k = k * 2 + 1; for (int i = 0; i = k) s -= a[i - k]; s += a[i]; if (s > ..
백준 1940번
·
Study/Algorithm
https://www.acmicpc.net/problem/1940 1940번: 주몽 첫째 줄에는 재료의 개수 N(1 ≤ N ≤ 15,000)이 주어진다. 그리고 두 번째 줄에는 갑옷을 만드는데 필요한 수 M(1 ≤ M ≤ 10,000,000) 주어진다. 그리고 마지막으로 셋째 줄에는 N개의 재료들이 가진 고 www.acmicpc.net #include #include #include using namespace std; int main() { int N, M; vector arr; cin >> N >> M; arr.resize(N); for (int i = 0; i > arr[i]; } sort(arr.begin(), arr.end()); int start = 0, end ..
백준 2003번
·
Study/Algorithm
https://www.acmicpc.net/problem/2003 2003번: 수들의 합 2 첫째 줄에 N(1 ≤ N ≤ 10,000), M(1 ≤ M ≤ 300,000,000)이 주어진다. 다음 줄에는 A[1], A[2], …, A[N]이 공백으로 분리되어 주어진다. 각각의 A[x]는 30,000을 넘지 않는 자연수이다. www.acmicpc.net #include #include "vector" using namespace std; vector board; int main() { int N, M; cin >> N >> M; for (int i = 0; i > input; board.push_back(input); } board.push_back(0);..
백준 21921번
·
Study/Algorithm
https://www.acmicpc.net/problem/21921 21921번: 블로그 첫째 줄에 $X$일 동안 가장 많이 들어온 방문자 수를 출력한다. 만약 최대 방문자 수가 0명이라면 SAD를 출력한다. 만약 최대 방문자 수가 0명이 아닌 경우 둘째 줄에 기간이 몇 개 있는지 출력한다 www.acmicpc.net #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, X; cin >> N >> X; int arr[250001]; for (int i = 0; i > arr[i]; int start = 0, end = start + X - 1; i..
백준 20922번
·
Study/Algorithm
https://www.acmicpc.net/problem/20922 20922번: 겹치는 건 싫어 홍대병에 걸린 도현이는 겹치는 것을 매우 싫어한다. 특히 수열에서 같은 원소가 여러 개 들어 있는 수열을 싫어한다. 도현이를 위해 같은 원소가 $K$개 이하로 들어 있는 최장 연속 부분 수열 www.acmicpc.net #include using namespace std; int N, K; int cnt[100005]; int arr[200005]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N >> K; for (int i = 1; i > arr[i]; int start = 1, end = 1; int ans = 0; while ..
백준 15489번
·
Study/Algorithm
https://www.acmicpc.net/problem/15489 15489번: 파스칼 삼각형 첫째 줄에 양의 정수 R, C, W가 공백을 한 칸씩 두고 차례로 주어진다. (단, 2 ≤ R+W ≤ 30, 2 ≤ C+W ≤ 30, 1 ≤ W ≤ 29, C ≤ R) www.acmicpc.net #include using namespace std; int main() { int dp[31][31]; int R, C, W; cin >> R >> C >> W; for (int i = 1; i
백준 16953번
·
Study/Algorithm
https://www.acmicpc.net/problem/16953 16953번: A → B 첫째 줄에 A, B (1 ≤ A > input1 >> input2; while (input2 >= input1) { if (input2 == input1) { cout
백준 14916번
·
Study/Algorithm
https://www.acmicpc.net/problem/14916 14916번: 거스름돈 첫째 줄에 거스름돈 액수 n(1 ≤ n ≤ 100,000)이 주어진다. www.acmicpc.net #include using namespace std; int main() { int money, result; cin >> money; bool success = false; int five = money / 5; while (!success) { float two = (money - five * 5) % 2; if (two == 0) { success = true; result = five + (money - five * 5) / 2; } else { five--; } } if (money == 1 || money..