Cod sursa(job #1467110)

Utilizator irinel132Ghita Costinel Irinel irinel132 Data 2 august 2015 19:42:14
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <fstream>
using namespace std;

int n, m;
int zile[1001];                    // Suma de bani inca neachitata pentru o comanda efectuata in ziua i

int main () {
    ifstream    fin;
    ofstream    fout;

    fin.open("datorii.in");
    fout.open("datorii.out");

    fin >> n;
    fin >> m;

    for (int i = 0; i < n; i++) { fin >> zile[i + 1]; }

    int tip;
    int a, b;

    for (int i = 0; i < m; i++) {
        fin >> tip;
        fin >> a;
        fin >> b;

        if (tip == 0) {
            // Operatie de tip A
            zile[a] -= b;
        } else {
            // Operatie de tip B
            int suma = 0;

            for (int j = a; j <= b; j++) { suma += zile[j]; }

            fout << suma << "\n";
        }
    }

    fin.close();
    fout.close();

    return 0;
}