公式
D - Parking 2 解説 by en_translator
The fee within the \(h\) o’clock (from exactly \(h\) o’clock to exactly \((h+1)\) o’clock) can be computed as follows:
- \(X\) if \(L \leq h \leq R-1\)
- \(Y\) otherwise
For the integer \(h\), run a loop within the range \(A \leq h \leq B-1\), find the fee within \(h\) o’clock as described above, and sum them up.
Sample code (C++)
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
int main (void) {
int x, y, l, r, a, b;
cin >> x >> y >> l >> r >> a >> b;
int sum = 0;
for (int i = a; i <= b-1; i++) {
// cost of i-th hour
if (l <= i && i <= r-1) {
sum += x;
} else {
sum += y;
}
}
cout << sum << "\n";
return 0;
}
投稿日時:
最終更新: