Profit magazin

Calculează profitul zilnic și total pentru un magazin.

  • Citim numărul de zile n

  • Pentru fiecare zi, citim venitul și cheltuiala

  • Calculăm profitul zilnic și îl adăugăm la profitul total

  • Ținem evidența zilei cu profitul maxim

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

int main() {
    int n, venit, cheltuiala;
    cin >> n;
    
    int profit_total = 0;
    int profit_maxim = -1000000;
    int zi_max = 0;
    
    for(int i = 1; i <= n; i++) {
        cin >> venit >> cheltuiala;
        int profit = venit - cheltuiala;
        profit_total += profit;
        
        if(profit > profit_maxim) {
            profit_maxim = profit;
            zi_max = i;
        }
    }
    
    cout << "Profit total: " << profit_total << endl;
    cout << "Zi profit maxim: " << zi_max << endl;
    
    return 0;
}
2
12
23
1
2
Profit total: -12
Zi profit maxim: 2