-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #452 from jimi567/master
2283 구간 자르기
- Loading branch information
Showing
1 changed file
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
// Authored by : BaaaaaaaaaaarkingDog | ||
// Co-authored by : - | ||
// http://boj.kr/**************** | ||
// Authored by : jimi567 | ||
// Co-authored by : BaaaaaaaaaaarkingDog | ||
// http://boj.kr/dfd3c41769e94f5bb45a328e1379121c | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main(void){ | ||
using ll = long long; | ||
int n, k; | ||
int arr[1000005]; // arr[i] : arr[i]에 있는 선분의 개수 | ||
|
||
int main(void) { | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
|
||
} | ||
cin.tie(0); | ||
cin >> n >> k; | ||
for (int i = 0; i < n; i++) { | ||
int st, en; | ||
cin >> st >> en; | ||
for (int j = st; j < en; j++) | ||
arr[j]++; | ||
} | ||
int en = 0; | ||
int tot = arr[0]; | ||
for(int st = 0; st < 1000000; st++){ | ||
while(en < 1000000 && tot < k){ | ||
en++; | ||
if(en != 1000000) tot += arr[en]; | ||
} | ||
if(en == 1000000) break; | ||
if(tot == k){ | ||
cout << st << ' ' << en + 1; | ||
return 0; | ||
} | ||
tot -= arr[st]; | ||
} | ||
cout << 0 << ' ' << 0; | ||
return 0; | ||
} | ||
/* | ||
구간 정보를 arr라는 배열을 이용해 옮기고 나면 BOJ 1806번: 부분합과 | ||
유사한 문제가 된다. | ||
*/ |