mardi 15 août 2023

I'm doing a project at school by C++ and seems like it has a problem with data byte. I've created some variations with long and assigned them to each other.

But the system has reported an error: [Error] invalid conversion from 'long int*' to 'long int' [-fpermissive]

Here is the function

int main()
{
    pair <long,long> a[1001];
    long ps[1001], b[1001];
    long n,m,l,r, L, R;
    cin >> n >> m;
    ps[0]=0;
    for(long i=1; i<=n; i++)
    {
        cin >> a[i].second >> a[i].first;
        ps[i]=ps[i-1]+a[i].second;
        b[i]=a[i].first;
    }
    sort(a+1,a+n);
    while(m--)
    {
        cin >> l >> r;
        L=lower_bound(b+1,b+n+1,l);
        R=upper_bound(b+1,b+n+1, r);
        cout << ps[R]-ps[L-1];
    }
}

Aucun commentaire:

Enregistrer un commentaire