if_will_else @ 2023-11-22 16:53:11
#include<bits/stdc++.h>
using namespace std;
int n;
int a[5010];
int cnt=0;
bool runnian(int nian) {
if(nian%4==0&&nian%100!=0)
return 1;
else if(nian%400==0)
return 0;
return 1;
}
int main() {
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
int n1,y1,r1,s1,f1;
int n2,y2,r2,s2,f2;
scanf("%d-%d-%d-%d:%d",&n1,&y1,&r1,&s1,&f1);
scanf("%d-%d-%d-%d:%d",&n2,&y2,&r2,&s2,&f2);
int nc=n2-n1,yc=y2-y1,rc=r2-r1,sc=s2-s1,fc=f2-f1;
// cout<<nc<<" "<<yc<<" "<<rc<<" "<<sc<<" "<<fc;
long long mc=0;
if((!runnian(n1))&&(!runnian(n2)))
mc=nc*525600+yc*43200+rc*1440+sc*60+fc;
else if(runnian(n1)&&y1<=3&&r1<27)
mc=nc*525600+yc*43200+rc*1440+sc*60+fc;
else if(runnian(n2)&&y2>=3)
mc=nc*525600+yc*43200+rc*1440+sc*60+fc;
else
mc=nc*525600+yc*43200+(rc+1)*1440+sc*60+fc;
// cout<<mc;
sort(a+1,a+1+n);
int i=1;
while(mc-a[i]>=0) {
mc-=a[i++];
cnt++;
}
printf("%d",cnt);
return 0;
}