AKPC @ 2022-08-04 10:08:31
#include <bits/stdc++.h>
using namespace std;
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
int n,a[100001],t[2][5],times=0,day=0,ans=0,q=0;
int rn(int x){
if(x%400==0) return 1;
if(x%100==0) return 0;
if(x%4==0) return 1;
return 0;
}
void tmer(){
for (int i=t[0][0]+1;i<t[1][0];i++) day+=365+rn(i);
if (t[0][0]!=t[1][0]){
for (int i=t[0][1];i<12;i++) (bool)rn(t[0][0])?day+=month[1][i-1]:day+=month[0][i-1];
for (int i=1;i<t[1][1];i++) (bool)rn(t[1][0])?day+=month[1][i-1]:day+=month[0][i-1];
}
else if (t[0][1]!=t[1][1]) for (int i=t[0][1];i<t[1][1];i++) (bool)rn(t[0][0])?day+=month[1][i-1]:day+=month[0][i-1];
day+=t[1][2]-t[0][2];
times+=day*(int)1440;
times+=(t[1][3]-t[0][3])*60;
times+=t[1][4]-t[0][4];
// cout<<times<<endl;
}
int main(){
cin>>n;
for (int i=0;i<n;i++) cin>>a[i];
scanf("%d-%d-%d-%d:%d",&t[0][0],&t[0][1],&t[0][2],&t[0][3],&t[0][4]);
scanf("%d-%d-%d-%d:%d",&t[1][0],&t[1][1],&t[1][2],&t[1][3],&t[1][4]);
tmer();
sort(a,a+n);
while (q<n){
if (times>=a[q]) {ans++;times-=a[q++];}
else break;
}
cout<<ans;
}