-
-
Save ampulhetadosaber/2718823cd4b913d16ca3c8ae87e2a857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int v[1000000]; | |
int n,m; | |
int main() | |
{ | |
cin >> n >> m; //Quantidade de elementos no vetor v e a quantidade de perguntas m | |
for(int i = 1 ; i <= n ; i++) | |
{ | |
cin >> v[i]; //O número na posição i do vetor | |
} | |
for(int i = 1; i <= m ; i++) | |
{ | |
int l,r; //O intervalo de l até r | |
cin >> l >> r; | |
//Percorro esse intervalo somando todos os elementos em uma variavel resposta | |
int resposta = 0; | |
for(int j = l ; j <= r ; j++) | |
{ | |
resposta = resposta + v[j]; | |
} | |
cout << "No intervalo de" << l << " ate " << r << " a soma e " << resposta << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment