站外题目求助 题目:
Problem Statement
In the Kingdom of AtCoder, a week consists of A+B days, with the first through A-th days being holidays and the (A+1)-th through (A+B)-th being weekdays.
Takahashi has N plans, and the i-th plan is scheduled Di days later.
He has forgotten what day of the week it is today. Determine if it is possible for all of his N plans to be scheduled on holidays.
代码:
#include <iostream>
#include <algorithm>
using namespace std;
long long n, a, b, d[200007], flag;
int main()
{
cin >> n >> a >> b;
for (int i = 0; i < n; ++i) cin >> d[i];
for (int i = 0; i < n; ++i)
{
d[i] %= (a + b);
}
sort(d, d + n);
long long num = max(0 * 1ll, d[n - 1] - a) - 1;
while (num++ <= (a + b))
{
if (!(d[n - 1] - a - num <= 0 && d[n - 1] - a - num >= -a + 1)) continue;
else if (!(d[0] - a - num <= 0 && d[0] - a - num >= -a + 1)) continue;
else
{
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}