Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Intervals
- {
- class Program
- {
- private static void Summ(long[] summ, string interval)
- {
- Console.WriteLine(summ[int.Parse(interval.Split()[1])]-summ[int.Parse(interval.Split()[0])-1]);
- }
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var elems = new int[n+1];
- elems[0] = 0;
- for (int i = 1; i <= n; i++)
- elems[i] = int.Parse(Console.ReadLine());
- var summ = new long[n+1];
- summ[0] = 0;
- for (int i = 1; i <= n; i++)
- summ[i] = summ[i - 1] + elems[i];
- int q = int.Parse(Console.ReadLine());
- var intervals = new string[q];
- for (int i = 0; i < q; i++)
- intervals[i] = Console.ReadLine();
- foreach (var e in intervals)
- Summ(summ, e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement