【悬关】70分求助!#7 WA

P1167 刷题

demons1014 @ 2024-07-25 17:50:17

#include<bits/stdc++.h>

using namespace std;

bool is_prime_year(long long int year)
{
    if (year == 3200)
    {
        return false;
    }
    if (year % 100 == 0)
    {
        return year % 400 == 0;
    }
    else
    {
        return year % 4 == 0;
    }
}

int main()
{

    //freopen("P1167_7.in", "r", stdin); freopen("P1167_7_2.out", "w", stdout);
    long long int n;
    long long int cnt = 0;
    long long int year1, month1, day1, hour1, min1;
    long long int year2, month2, day2, hour2, min2;
    long long int total_min1 = 0, total_min2 = 0;

    //vector<long long int> a(5005);
    vector<long long int> a;

    scanf("%lld", &n);

    for (long long int i = 0; i < n; i++)
    {
        long long int tmp;
        scanf("%lld", &tmp);
        a.push_back(tmp);
    }

    scanf("%lld-%lld-%lld-%lld:%lld", &year1, &month1, &day1, &hour1, &min1);
    scanf("%lld-%lld-%lld-%lld:%lld", &year2, &month2, &day2, &hour2, &min2);

    for (long long int i = 0; i < year1; i++)
    {
        if (is_prime_year(i))
        {
            total_min1 += 526040;
        }
        else
        {
            total_min1 += 525600;
        }
    }
    for (long long int i = 0; i < year2; i++)
    {
        if (is_prime_year(i))
        {
            total_min2 += 526040;
        }
        else
        {
            total_min2 += 525600;
        }
    }

    for (long long int i = 1; i < month1; i++)
    {
        if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
        {
            total_min1 += 44640;
        }
        else if (i == 2)
        {
            if (is_prime_year(year1))
            {
                total_min1 += 41760;
            }
            else
            {
                total_min1 += 40320;
            }
        }
        else
        {
            total_min1 += 43200;
        }
    }

    for (long long int i = 1; i < month2; i++)
    {
        if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
        {
            total_min2 += 44640;
        }
        else if (i == 2)
        {
            if (is_prime_year(year2))
            {
                total_min2 += 41760;
            }
            else
            {
                total_min2 += 40320;
            }
        }
        else
        {
            total_min2 += 43200;
        }
    }

    total_min1 += day1 * 1440;
    total_min2 += day2 * 1440;

    total_min1 += hour1 * 60;
    total_min2 += hour2 * 60;

    total_min1 += min1;
    total_min2 += min2;

    long long int tmp = total_min2 - total_min1;
    //cout << total_min1 << ' ' << total_min2 << '\n';
    //cout << tmp << ' ';
    sort(a.begin(), a.end());
    for (long long int i = 0; i < n; i++)
    {
        if (tmp >= a[i])
        {
            cnt++;
            tmp -= a[i];
        }
        else
        {
            break;
        }
    }
    //cout << cnt;
    printf("%lld\n", cnt);
    //fclose(stdin); fclose(stdout);
    //cout << is_prime_year(3200);
}

RT, 测试点输入,输出为1140。


|