Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Solve Using C++ King Arthur is throwing a party! He secretly hides a priz

ID: 3937998 • Letter: P

Question

Please Solve Using C++

King Arthur is throwing a party! He secretly hides a prize under each chair of the famous round table. In case you don't know, this is a table with n chairs (for each of the n knights) arranged in a circle.

But there is a problem, he has forgotten which knight sits in which chair.

He remembers the order the knights sit in. If we number the knights from 0 to n-1, Knight 1 always sits to the right of knight 0, knight 2 always sits to the right of knight 1, and so on. That is, for 1 i n-1 Arthur knows that knight i sits to the right of knight i-1. Also, knight 0 sits to the right of knight n-1.

Arthur thinks knight 0 sits in chair 0. But this might be wrong. In reality, knight 0 sits in chair s where 0 s n-1.

Finally, Arthur is friends some of these knights. Your job is to figure out the total value of the prizes collected by Arthur's friends.

Input

Input consists of three lines.

The first line contains three integers n, k, s (in that order).

Here, n is a positive integer at most 100,000 indicating the number of chairs (and knights), k is a positive integer at most n indicating how many knights are Arthur's friends, and s is an integer between 0 and n-1 indicating that knight 0 actually sits in chair s.

The second line contains n integers denoting the values of the prizes. The i'th integer (starting from i = 0) is the value of the prize hidden under chair i. Each integer on this line is a value between -20,000 and 20,000; some "prizes" may actually be punishments like a pay deduction.

The last line contains k distinct integers between 0 and n-1 indicating which knights are Arthur's friends.

In each line, consecutive integers are separated by a single space.

Output

Output a single line containing a single integer denoting the total value of prizes obtained by Arthur's friends.

Sample Input

Sample Output

Description of Sample Data

Knights 0, 1, and 2 are sitting in chairs 1, 2, and 3 (respectively) so they obtain a total value of 2 + (-1) + 6 = 7.

Knights 3, 6, and 4 are sitting in chairs 3, 6, and 4 (Arthur got it right this time!) so they obtain a total value of 4 + 7 + 1 = 12.

Knights 1, 4, 6, and 2 are sitting in chairs 6, 2, 4, and 0 (respectively) so they obtain a total value of (-3) + 3 + (-1) + 1 = 0.

The only knight is sitting in the only chair, and the prize has no value.

Explanation / Answer

#include"iostream"
using namespace std;
#include<string.h>
int main()
{
        int n,k,s;
        cin>>n>>k>>s;
        int prize[100000],knight[k],final_prize=0;
        int j,l,m;
//        cout<<n<<k<<s;
        if(k>n)
                cout<<"Can't Possible more knight than n Chairs ";

        if((s>n) || (s < 0))
                cout<<"Chair number should be grater than Zero and less than chairs (n-1) ";


        for(j=0;j<n;j++){
                cin>>prize[j];
                if((prize[j] > 20000) || (prize[j] < -20000))
                        cout<<"Error: Prize money out of limit ";
//                cout<<prize[j];
        }
        for(j=0;j<k;j++){
                cin>>knight[j];
                if(knight[j] < 0 && knight[j] > n-1)
                        cout<<"Error: Knight friend value should be 0 to n-1 ";
//                cout<<knight[j];
        }
        for(m=0;m<k;m++)
        {
//                for(l=s;;l++)
//                {                                      
                        l = s;
                        l += knight[m];
                        if(l>n-1)
                                l=l-n;                      
                        final_prize += prize[l];
//                        if(l==s-1 || l== -1)
//                              break;
//                }
        }
        cout<<final_prize;
        return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote