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
- 10819 파이썬
- 코루틴 플로우
- Android mvp
- 백준 1644
- 5582 DP
- flow buffering
- 안드로이드 hilt
- Coroutine Flow
- git local remote
- android hilt
- 6588 파이썬
- 투포인터 알고리즘
- 이진 탐색
- 1806 투포인터
- 1644 파이썬
- java
- 1806 파이썬
- 1753 파이썬
- Android Room
- Jetpack Room
- 1806 백준
- 1753 다익스트라
- 자바
- 2096 파이썬
- 1003 파이썬
- 자료구조
- 5582 파이썬
- 백준 2096
- 백준 5582
- 백준 10819
Archives
- Today
- Total
Gemstone's Devlog
[Codeforces] 1285B: Just Eat It! 본문
이 문제는 prefix sum 알고리즘으로 풀어야 하는 문제이다.
소스코드
#include <bits/stdc++.h>
using namespace std;
int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
long long a[100001];
long long p[100001];
long long m[100001]; // a[i]에서 끝나는 제일 큰 합
long long t, n, total, mn, ans;
cin >> t;
while (t > 0) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
p[0] = 0;
for (int i = 1; i <= n; i++) {
p[i] = p[i-1] + a[i];
}
total = p[n];
ans = 1;
mn = 0;
for (int i = 1; i < n; i++) {
m[i] = p[i] - mn;
mn = min(mn, p[i]);
if (m[i] >= total) ans = 0;
}
for (int i = 1; i <= n; i++) {
p[i] -= a[1];
}
mn = 0;
for (int i = 2; i <= n; i++) {
m[i] = p[i] - mn;
mn = min(mn, p[i]);
if (m[i] >= total) ans = 0;
}
if (ans == 1) cout << "YES" << endl;
else cout << "NO" << endl;
t--;
}
return 0;
}
'Data Structure & Algorithms' 카테고리의 다른 글
[백준] 1339번: 단어 수학 (그리디) (0) | 2022.03.24 |
---|---|
[백준] 14889번: 스타트와 링크 (백트래킹) (0) | 2022.03.13 |
[백준] 1932번: 정수 삼각형 (다이나믹 프로그래밍) (0) | 2022.03.02 |
[이것이 코딩테스트다] 효율적인 화폐 구성 (0) | 2022.03.01 |
[백준] 1463번: 1로 만들기 (다이나믹 프로그래밍) (0) | 2022.02.27 |