Pagini recente » Cod sursa (job #1575794) | Cod sursa (job #2610753) | Cod sursa (job #265542) | Cod sursa (job #96615) | Cod sursa (job #3133450)
#include <iostream>
#include <vector>
#include <fstream>
void calcDebt(int N, int M, std::vector<int>& debts, std::vector<std::vector<int>>& ops, std::ofstream& out) {
for (const auto& operation : ops) {
int opType = operation[0];
if (opType == 0) {
int day = operation[1];
int amount = operation[2];
debts[day] -= amount;
}
else if (opType == 1) {
int startDay = operation[1];
int endDay = operation[2];
int totalDebt = 0;
for (int day = startDay; day <= endDay; ++day) {
totalDebt += debts[day];
}
out << totalDebt << std::endl;
}
}
}
int main() {
std::ifstream in("datorii.in");
std::ofstream out("datorii.out");
int N, M;
in >> N >> M;
std::vector<int> debts(N + 1);
for (int i = 1; i <= N; ++i) {
in >> debts[i];
}
std::vector<std::vector<int>> ops(M, std::vector<int>(3));
for (int i = 0; i < M; ++i) {
int opType;
in >> opType;
ops[i][0] = opType;
in >> ops[i][1] >> ops[i][2];
}
calcDebt(N, M, debts, ops, out);
return 0;
}