【題解】Codeforces EDU Course-2 Lesson-6-2 C. Very Easy Task

【題目敘述】
https://codeforces.com/edu/course/2/lesson/6/2/practice/contest/283932/problem/C

credit: LiuWilliam

#include <iostream>
#include <algorithm>

using namespace std;
 
int n, x, y;
long long int ptr1 = 0, ptr2 = 0;   // time of the two printers
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> x >> y;
     
    if (x > y) swap(x, y);
     
    n--; 
    while (n) {
        if (ptr1 <= ptr2) {
            ptr1 += x;
        } else {
            ptr2 += y;
        }
        n--;
    }
     
    cout << max(ptr1, ptr2) + x << "\n";
     
    return 0;
}
分享本文 Share with friends