티스토리 뷰
9465번: 스티커
첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스의 첫째 줄에는 n (1 ≤ n ≤ 100,000)이 주어진다. 다음 두 줄에는 n개의 정수가 주어지며, 각 정수는 그 위치에 해당하는 스티커의
www.acmicpc.net
백준 소스코드 [C++] 9465 스티커
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
typedef long long ll;
using namespace std;
int arr[2][100001], sum[2][100001];
void solve(int n) {
sum[0][0] = arr[0][0], sum[1][0] = arr[1][0];
for (int j = 0;j < n-1;j++) {
sum[0][j + 2] = max(sum[0][j + 2], sum[1][j] + arr[0][j + 2]);
sum[0][j + 1] = max(sum[0][j + 1], sum[1][j] + arr[0][j + 1]);
sum[1][j + 2] = max(sum[1][j + 2], sum[0][j] + arr[1][j + 2]);
sum[1][j + 1] = max(sum[1][j + 1], sum[0][j] + arr[1][j + 1]);
}
cout << max(sum[0][n - 1], sum[1][n - 1]) << '\n';
memset(sum, 0, sizeof(sum));
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0;i < 2;i++)for (int j = 0;j < n;j++) cin >> arr[i][j];
solve(n);
}
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 2407 조합 (0) | 2020.10.29 |
---|---|
백준 소스코드 [C++] 15663 N과 M 9 (0) | 2020.10.29 |
백준 소스코드 [C++] 15989 1, 2, 3 더하기 4 (0) | 2020.10.28 |
백준 소스코드 [C++] 15993 1, 2, 3 더하기 8 (0) | 2020.10.28 |
백준 소스코드 [C++] 11598 1, 2, 3 더하기 3 (0) | 2020.10.28 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- WWDC17
- 코딩대회
- 벨만포드 시간복잡도
- 벨만포드 알고리즘
- 최단경로 알고리즘
- WWDC21
- test coverage
- observeOn
- CompositionalLayout
- 에드몬드 카프 알고리즘
- Testable
- WWDC16
- 최단경로문제
- 네트워크 유량
- 컴퓨터 추상화
- HIG
- rxswift
- State Restoration
- 포드 풀커슨 알고리즘
- 강한 순환 참조
- MeTal
- 부스트캠프 6기
- IOS
- 최단경로 문제
- 다익스트라 시간복잡도
- mach-o
- 최대 매칭
- CPU와 Memory
- 네트워크 플로우
- WWDC19
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
글 보관함