代码:(CE)
#include<bits/stdc++.h>
using namespace std;
int n,a[6000],i,timee,c;
struct node{
int year;
int month;
int day;
int hour;
int minute;
}begin,end;
int month_num(int begin1,int end1){
int ans=0;
for (int i=begin1;i<end1;i++){
if (i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12)
ans+=31;
else if (i==4 || i==6 || i==9 || i==11)
ans+=30;
else if (end.year%4==0 && end.year%100 || end.year%400==0)
ans+=29;
else ans+=28;
}
return ans;
}
int main(){
scanf("%d",&n);
for (i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%d-%d-%d-%d:%d",&begin.year,&begin.month,
&begin.day,&begin.hour,&begin.minute);
scanf("%d-%d-%d-%d:%d",&end.year,&end.month,
&end.day,&end.hour,&end.minute);
timee=(end.year-begin.year)*60*24*365
+month_num(begin.month,end.month)
+(end.day-begin.day)*60*24
+(end.hour-begin.hour)*60
+(end.minute-begin.minute);
sort(a+1,a+1+n);
i=1;
while (c<timee) c+=a[i++];
if (c==timee) printf("%d",c);
else printf("%d",c+1);
return 0;
}