Untitled

mail@pastecode.io avatar
unknown
plain_text
3 months ago
535 B
1
Indexable
Never
#include <iostream>

typedef long long ll;
using namespace std;

ll diem(int a, int b, int n){
    if(b-a+1 >= n)
        return 1ll*n*(a+b)/2;
    ll s = 1ll*(b-a)*(a+1+b)/2;
    n -= b-a;
    s += 1ll*n/2*(a-n/2+1+a);
    if(n%2 != 0) s += a-1;
    return s;
}

int main(){
    freopen("BAI1.INP","r",stdin);
    freopen("BAI1.OUT","w",stdout);

    int a, b, n; cin >> a >> b >> n;
    if(a > b){
        int tmp = b;
        b = a;
        a = tmp;
    }
    cout << diem(a,b,n) << endl;

	return 0;
}
Leave a Comment