File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 590
590
| 47 | [ 키 큰 사람] ( https://www.acmicpc.net/problem/11292 ) | [ cpp] ( source/11292.cpp ) | 48 | [ 좌표 압축] ( https://www.acmicpc.net/problem/18870 ) | [ cpp] ( source/18870.cpp ) |
591
591
| 49 | [ 두 수의 합] ( https://www.acmicpc.net/problem/3273 ) | [ cpp] ( source/3273.cpp ) | 50 | [ 게으른 백곰] ( https://www.acmicpc.net/problem/10025 ) | [ cpp] ( source/10025.cpp ) |
592
592
| 51 | [ 약속] ( https://www.acmicpc.net/problem/1183 ) | [ cpp] ( source/1183.cpp ) | 52 | [ 효정과 새 모니터] ( https://www.acmicpc.net/problem/20949 ) | [ cpp] ( source/20949.cpp ) |
593
+ | 53 | [ 수열] ( https://www.acmicpc.net/problem/2559 ) | [ cpp] ( source/2559.cpp ) | | | |
593
594
594
595
</details >
595
596
Original file line number Diff line number Diff line change
1
+ // 2559. 수열
2
+ // 2022.05.01
3
+ // 투 포인터
4
+ #include < iostream>
5
+ #include < algorithm>
6
+
7
+ using namespace std ;
8
+
9
+ int arr[100000 ];
10
+
11
+ int main ()
12
+ {
13
+ int n, k;
14
+ cin >> n >> k;
15
+
16
+ for (int i = 0 ; i < n; i++)
17
+ {
18
+ cin >> arr[i];
19
+ }
20
+
21
+ int sum = 0 ;
22
+ int idx = 0 ;
23
+ int ans = -987654321 ;
24
+ for (int i = 0 ; i < n; i++)
25
+ {
26
+ sum += arr[i];
27
+ idx++;
28
+ if (idx == k)
29
+ {
30
+ ans = max (ans, sum);
31
+
32
+ // two pointer
33
+ sum -= arr[i - k + 1 ];
34
+ idx--;
35
+ }
36
+ }
37
+ cout << ans << endl;
38
+ return 0 ;
39
+ }
You can’t perform that action at this time.
0 commit comments