I consider using an array to store the mail number at every second in the day, so length is 86400.
I don't think there is any problem in my code, but got SIGSEGV, could anybody tell my why please??
Thank you
#include "cstdio"
#include "cstring"
#include "queue"
using namespace std;
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
inline void inp(int &n){
n = 0;
int sign = 1;
char ch = gc();
while (ch < '0' || ch > '9'){
if (ch == '-')
sign = -1;
ch = gc();
}
while (ch >= '0' && ch <= '9'){
n = (n << 3) + (n << 1) + ch - '0';
ch = gc();
}
n = n * sign;
}
inline void outp(int n){
char buf[22];
if (n < 0){
pc('-');
n = -n;
}
int i = 0;
do {
buf[i++] = n % 10 + '0';
n = n / 10;
} while (n);
--i;
while (i >= 0)
pc(buf[i--]);
}
int main(){
int cases;
// inp(cases);
scanf("%d", &cases);
int arr[86400];
int current = 1;
if (cases == 0){
printf("Case 0: 0\n");
return 0;
}
while (current <= cases){
int n;
scanf("%d", &n);
// inp(n);
if (n == 0){
printf("Case %d: %d\n", current, 0);
// printf("Case ");outp(current);printf(": ");outp(0);pc('\n');
continue;
}
memset(arr,0,86400*sizeof(int));
int h,m,s;
while (n--){
// inp(h);inp(m);inp(s);
scanf("%d:%d:%d",&h,&m,&s);
int index = h*3600+m*60+s;
++arr[index];
}
int t;
// inp(t);
scanf("%d",&t);
int head = 1, tail = head + t - 1;
if (tail > 86399)
tail = 86399;
int ans = 0;
for (int i = head; i <= tail; ++i)
ans += arr[i];
++head;
++tail;
int tmp = ans;
while (tail <= 86399){
tmp = tmp + arr[tail] - arr[head];
if (ans < tmp)
ans = tmp;
++head;
++tail;
}
printf("Case %d: %d\n", current, ans);
// printf("Case ");outp(current);printf(": ");outp(ans);pc('\n');
++current;
}
return 0;
}