[BOJ] 3985 롤 케이크

Time Lapse :NONE

3985.cpp

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
31
32
33
34
35
36
#include <iostream>
#include <memory.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int L, N;
cin>>L>>N;
bool cake[L+1];
int answer1, answer2;
int most_expected = 0;
int most_get = 0;
int from,to;
int get = 0;
memset(cake,false,sizeof(cake));
for(int i=1;i<=N;i++){
cin>>from>>to;
if(most_expected<(to-from+1)){
most_expected = to-from+1;
answer1 = i;
}
get = 0;
for(int k=from;k<=to;k++){
if(!cake[k]){
cake[k]=true;
++get;
}
}
if(most_get<get){
most_get = get;
answer2 = i;
}
}
cout<<answer1<<endl<<answer2<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/3985/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.