#54563: C++題解


MillionJudge (Millionaire is Online)


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long A1, B1, C1, A2, B2, C2;
    int n;
    cin >> A1 >> B1 >> C1;
    cin >> A2 >> B2 >> C2;
    cin >> n;

    long long best = -(1LL<<62);

    for (int x1 = 0; x1 <= n; x1++) {
        int x2 = n - x1;
        long long y1 = A1 * x1 * x1 + B1 * x1 + C1;
        long long y2 = A2 * 1LL * x2 * x2 + B2 * x2 + C2;
        best = max(best, y1 + y2);
    }

    cout << best << "\n";
    return 0;
}