Submission #3610426


Source Code Expand

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

int64_t price(int a, int b, int t){
    return max(b, b+t-a);
}

int main(){
    int N, M;
    cin >> N;
    vector<pair<int, int>> ab(N);
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        ab[i] = {a, b};
    }
    sort(ab.begin(), ab.end());

    cin >> M;
    while(M--){
        int t;
        cin >> t;
        int i = lower_bound(ab.begin(), ab.end(), make_pair(t, 0)) - ab.begin();
        int64_t ans = 1e18;
        if(i > 0) ans = min(ans, price(ab[i-1].first, ab[i-1].second, t));
        if(i < N) ans = min(ans, price(ab[i].first, ab[i].second, t));
        cout << ans << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task C - Telephone Charge
User betrue12
Language C++14 (GCC 5.4.1)
Score 300
Code Size 715 Byte
Status
Exec Time 309 ms
Memory 2048 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt
All 300 / 300 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
01.txt 295 ms 2048 KB
02.txt 309 ms 2048 KB
03.txt 256 ms 1664 KB
04.txt 172 ms 1408 KB
05.txt 293 ms 1920 KB
06.txt 270 ms 1792 KB
07.txt 301 ms 2048 KB
08.txt 96 ms 768 KB
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB