Find the sum of an inside array of a bigger array

I have this code:

#include <iostream>
using namespace std;

int tc; int tv;
int array[1000000];
void Input(){
    scanf("%d\n",&tc);
    for (int i = 0;i<tc;i++){
        scanf("%d",&array[i]);
    }
    scanf("\n");
    scanf("%d\n",&tv);
}
void XuLi(){
    Input();
    int a,b;
    for (int i = 0;i<tv;i++){
        scanf("%d %d\n",&a,&b);
        a--; b--;
        int sum = 0;
        for (int i = a;i<=b;i++){
            sum+=array[i];
        }
        printf("%d\n",sum);
    }
}

int main(){
    freopen("doanlt.inp","r",stdin); freopen("doanlt.out","w",stdout);
    XuLi(); return 0;
}

How can I optimize it?
The testcases are about 10^6 tries.

I am not sure what this function is supposed to do. If you are summing all values in a range, there is a formula for that.