結果

問題 No.2208 Linear Function
ユーザー evima
提出日時 2023-04-06 01:39:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 69,716 KB
最終ジャッジ日時 2025-02-11 23:14:19
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int t;
    cin >> t;

    while (t--) {
        int l, r, a, b;
        cin >> l >> r >> a >> b;

        int ans;
        if (a == 0) {  // aが0のときはxに関係なくBが最大値
            ans = b;
        } else if (a > 0) {  // aが正のときはx=Rのときに最大値を取る
            ans = max(a*l + b, a*r + b);
        } else {  // aが負のときはx=Lのときに最大値を取る
            ans = max(a*l + b, a*r + b);
        }

        cout << ans << endl;
    }

    return 0;
}
0