Monday, December 30, 2013

codechef HOTEL - "hotel bytelandia" solution

codechef HOTEL - "hotel bytelandia": http://www.codechef.com/problems/HOTEL

codechef HOTEL - "hotel bytelandia" solution: http://ideone.com/CGE5AA

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
// your code goes here
int t, n, arr[105], dep[105], hr, count, max;
scanf("%d", &t);
while(t--) {
scanf("%d", &n); hr=0; count=0; max=0;
for(int i=0; i<n; i++) scanf("%d", &arr[i]);
for(int i=0; i<n; i++) scanf("%d", &dep[i]);
while(hr<1005) {
for(int i=0; i<n; i++) {
if(hr==arr[i]) count++; if(count>max) max=count;
if(hr==dep[i]) count--; 
} hr++;
}
printf("%d\n", max);
}
return 0;
}

codechef HOTEL - "hotel bytelandia" guidance:

start from hr=0; increase hour(hr++), if you encounter arrival(arr[i]) then increase guest(count++), if you encounter departure(dep[i]), then decrease guest(count--). meanwhile, keep record of maximum guest number(if(count>max) max=count). print out max.

1 comment: