lina_os

Untitled

Nov 12th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int main() {
  5. int n, q;
  6. cin >> n >> q;
  7. int a[n], b[2];
  8. for (int i = 0; i < n; i++) {
  9. cin >> a[i];
  10. }
  11. for (int i = 0; i < q; i++) {
  12. cin >> b[0] >> b[1];
  13. b[0]--;
  14. b[1]--;
  15. long long sum=0;
  16. for (int j = b[0]; j <= b[1]; j++) {
  17. sum += a[j];
  18. }
  19. cout << sum << endl;
  20. }
  21.  
  22.  
  23. return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment