Half and Half

Problem Link

Solution by Mr.Olimpia — 100 pts

Code / Notes

#include <bits/stdc++.h>
using namespace std;

// https://ide.usaco.guide/Ov5Bu8j7yJ_6itiOaT2

// P[3] = 5 -> o pai do 3 é o 5
// P[3] = -1 -> 3 não tem pai

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if(a+b>=2*c){
        if(x>=y){
            if(a>=2*c){
                cout << x*2*c;
            }
            else{
                cout << y*2*c + (x-y)*a;
            }
        }
        if(x<y){
            if(b>=2*c){
                cout << y*2*c;
            }
            else{
                cout << x*2*c + (y-x)*b;
            }
        }
    }
    else{
        cout << a*x+b*y;
    }
}

Last updated 1 month, 3 weeks ago


« Back to problem