116A - Tram Codeforces || Codeforces 116A - Tram Solution

Problem Name: Tram
Problem Code: 116A
Judge: Codeforces
Problem link: Tram
Solution on GitHub: Tram



Codeforces 116A - Tram Solution in C++/Cpp

#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int passengers[n][2];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> passengers[i][j];
        }
    }
    for (int i = 0; i < n - 1; i++) {
        passengers[i + 1][1] = (passengers[i][1] - passengers[i + 1][0]) + passengers[i + 1][1];
    }
    int max = passengers[1][1];
    for (int i = 1; i < n; i++) {
        if (passengers[i][1] > max) {
            max = passengers[i][1];
        }
    }
    if (max > 2) {
        cout << max << "\n";
    }
    else {
        int x = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                if (passengers[i][j] > x) {
                    x = passengers[i][j];
                }
            }
        }
        cout << x << "\n";
    }

    return 0;
}










Codeforces 116A - Tram solution in C C++, 116A codeforces solution in C C++, Codeforces 116A solution in C C++, Codeforces Tram solution in C C++, 116A - Tram Codeforces solution in C C++, Codeforces 116A - Tram solution in C C++, Codeforces, Codeforces Solution, CF, C, C++, Java, Python, Javascript, C#, Programming, Blog, Data Structure, Algorithm, DS.

Next Post Previous Post
No Comment
Add Comment
comment url