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
- 자료구조
- 다익스트라
- 백트래킹
- ue5
- 수학
- 유니온 파인드
- 알고리즘
- 문자열
- 그리디 알고리즘
- 구현
- c++
- 정렬
- 누적 합
- 스택
- 트리
- Unreal Engine 5
- 백준
- 시뮬레이션
- Team Fortress 2
- VR
- BFS
- 브루트포스
- 투 포인터
- 그래프
- 다이나믹 프로그래밍
- XR Interaction Toolkit
- 유니티
- 우선순위 큐
- 재귀
- DFS
Archives
- Today
- Total
1일1알
백준 21921번 블로그 C++ 본문
https://www.acmicpc.net/problem/21921
21921번: 블로그
첫째 줄에 $X$일 동안 가장 많이 들어온 방문자 수를 출력한다. 만약 최대 방문자 수가 0명이라면 SAD를 출력한다. 만약 최대 방문자 수가 0명이 아닌 경우 둘째 줄에 기간이 몇 개 있는지 출력한다
www.acmicpc.net
누적 합, 슬라이딩 윈도우
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, x;
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> x;
v = vector<int>(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int maxSum = 0;
int sum = 0;
int cnt = 0;
for (int i = 0; i < x; i++) {
sum += v[i];
}
maxSum = sum;
cnt = 1;
for (int i = x; i < n; i++) {
sum += v[i];
sum -= v[i - x];
if (sum > maxSum) {
maxSum = sum;
cnt = 1;
}
else if (sum == maxSum) {
cnt++;
}
}
if (maxSum == 0) cout << "SAD";
else cout << maxSum << "\n" << cnt;
}
'알고리즘' 카테고리의 다른 글
백준 4097번 수익 C++ (0) | 2023.02.13 |
---|---|
백준 19638번 센티와 마법의 뿅망치 C++ (0) | 2023.02.12 |
백준 2194번 유닛 이동시키기 C++ (0) | 2023.02.09 |
백준 1911번 흙길 보수하기 C++ (0) | 2023.02.08 |
백준 2258번 정육점 C++ (0) | 2023.02.07 |