/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 392.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 4ms 536.0 KiB
#5 Accepted 28ms 764.0 KiB
#6 Accepted 259ms 1.328 MiB
#7 Accepted 264ms 1.391 MiB
#8 Accepted 265ms 1.297 MiB
#9 Accepted 265ms 1.355 MiB
#10 Accepted 2ms 532.0 KiB

Code

#include <iostream>
using namespace std;

// Function to calculate the total accommodation fee for each test case
int calculate_fee(int N, int D, int A, int B) {
    if (N <= D) {
        return N * A;
    } else {
        return D * A + (N - D) * B;
    }
}

int main() {
    int T;
    
    // Input the number of test cases
    cin >> T;
    
    // Process each test case
    for (int i = 0; i < T; i++) {
        int N, D, A, B;
        
        // Input N (total nights) and D (discount nights)
        cin >> N >> D;
        
        // Input A (higher rate) and B (lower rate)
        cin >> A >> B;
        
        // Output the total accommodation fee for this test case
        cout << calculate_fee(N, D, A, B) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1090 Summer trip
Language
C++11 (G++ 13.2.0)
Submit At
2024-09-07 07:00:30
Judged At
2024-09-07 07:00:30
Judged By
Score
100
Total Time
265ms
Peak Memory
1.391 MiB