Codeforces Round #248 (Div. 2) B - Kuriyama Mirai's Stones Solution



 

Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,i,m,t,l,r;
    cin>>n;
    long long int  a[n+1],b[n+1],sum1[n+1],sum2[n+2];
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sum1[0]=0,sum2[0]=0;
    for(i=1; i<=n; i++)
        sum1[i]=sum1[i-1]+a[i];
    sort(b+1,b+n+1);
    for(i=1; i<=n; i++)
        sum2[i]=sum2[i-1]+b[i];
    cin>>m;
    for(i=0; i<m; i++)
    {
        cin>>t>>l>>r;

        if(t==1)
            cout<<sum1[r]-sum1[l-1]<<endl;
        else
            cout<<sum2[r]-sum2[l-1]<<endl;
    }
    return 0;
}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.