50分求调!!

P1167 刷题

GPAVL @ 2022-03-18 17:39:16

#include<bits/stdc++.h>  
using namespace std;
long long n,a[10000],y,year,m,m1,d,d1,h,h1,f,f1,r,p,s,c;
char e;
int main()  
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
cin>>y>>e>>m>>e>>d>>e>>h>>e>>f;
cin>>year>>e>>m1>>e>>d1>>e>>h1>>e>>f1;
if(f<f1) s+=f1-f;
else if(f>f1){
f1+=60;
h1--;
s+=f1-f;
}
if(h<h1) s+=(h1-h)*60;
else if(h>h1){
h1+=24;
d1--;
s+=(h1-h)*60;
}
if(year>y){
for(int i=y;i<=year;i++){
if((i%4==0&&i%100!=0)||(i%400==0)) r++;
else p++;
}
s+=r*366*24*60+p*365*24*60;
}
if(m<m1){
for(int i=m;i<m1;i++){
if((year%4==0&&year%100!=0&&i==2)||(year%400==0&&i==2)) s+=29*24*60;
else if(i==2) s+=28*24*60;
else if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) s+=31*24*60;
else s+=30*24*60;
}
}
else if(m>m1){
for(int i=m1;i<m;i++){
if((year%4==0&&year%100!=0&&i==2)||(year%400==0&&i==2)) s+=29*24*60;
else if(i==2) s+=28*24*60;
else if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) s-=31*24*60;
else s-=30*24*60;
}
}
if(d<d1) s+=(d1-d)*24*60;
else if(d>d1) s+=(d-d1)*24*60;
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
if(s<=0) break;
else{
s-=a[i];
c++;
}
}
cout<<c;
}

|