**The contest is over .My solution is considered wrong for given question I am unable to find the reason.
Please Help! ****
Ques1->Problem Description
Mr. Wick has a faulty keyboard. Some of the keys of the keyboard don't work. So, he has copied all those characters corresponding to the faulty keys on a clipboard from some existing document. Whenever those characters need to be typed, he pastes it from the clipboard. In typing whatever is required he needs to make use of paste, backspace and cursor traversal operations. Help him to minimize the number of operations he needs to do to complete his typing assignment. Each operation has one unit weightage.
Mr. Wick prefers verbal clarity over optimization of labour. That's why he prefers to fully process one word before processing the next word. This preference of his is very important to be honoured. Please see Example 1 in the examples section for better understanding.
Constraints
1 <= T <= 10^4
1 <= S <= 16
String T and S will only be comprised of letters a-z and digits 0-9
Input
First line contains text T to be typed
Second line contains string S of all the faulty keys pasted on clipboard
Output
Print the minimum number of operations required for typing the text T
Time Limit
1
Example 1
Input
experience was ultimate
ew
Output
14
Explanation
experience =(2+2+2+2) =[ {p+b} + {p+b} +{p+b} +{p+b} ]
was=(4)=[ p+m+b+m]
ultimate=(2)=[ p+b ]
where p=paste, b=backspace, m= move cursor
This is the right answer according to Mr. Wick's preference. However, this can also be done in another way. Since, this method does not honour Mr. Wick's preference this will be the wrong answer.
experiencew =(2+2+2+1) =[ {p+b} + {p+b} +{p+b} +{p}]
as =(0) =[]
ultimate=(2)=[ p+b ]
By this method the number of operations is only 9. However, this violates the constraint of fully processing one word before processing the next word. Hence, this is the wrong answer.
Example 2
Input
supreme court is the highest judicial court
su
Output
17
Explanation
supreme =(1) =[ p]
court=(4)=[ p+m+b+m]
is=(2)=[ p+b ]
the=(0)
highest=(2)= [p+b]
judicial=(4)= [p+m+b+m]
court=(4)= [p+m+b+m]
Solution->
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string t,s;
cin>>t;
cin>>s;
unordered_set<char>st;
for(int i=0;i<int(s.length());i++){
st.insert(s[i]);
}
long long sum=0;
long long i;
for(i=0;i<(long long)t.length();){
if(st.find(t[i])!=st.end()){
int f=0,j=0;
while(j<int(s.length())){
if(s[j]==t[i]){
j++;
i++;
f+=1;
}
else if(s[j]!=t[i] && f==0){
j++;
}
else{
break;
}
}
if(f==j){
sum+=(1+s.length()-f);
}
else {
sum+=(1+s.length()+f);
}
}
else{
i++;
}
}
cout <<sum<<endl;
return 0;
}
Ques2
Problem Description
An NGO wants to arrange funds for flood relief. It has divided volunteers into groups. A volunteer can only be a part of single group. Your task is to find the maximum funds collected by a group.
You will be given the funds collected by each volunteer and grouping pairs of the volunteers. You need to group the volunteers through these pairs.
Constraints
0 < N, P <= 10000
0 < A, B <= N
Input
First line contains one integer N, denoting number of volunteers.
Second line contains N space separated integers, representing the amount collected by each volunteer. The index of integer is the volunteer number starting from 1.
Third line contains the number of pairs, P.
Next P lines contain two space separated integers, A and B where A represents the first person and B represents the second person in the pair.
Output
One line containing an integer, representing the maximum funds collected by the group.
Time Limit
2
Example 1
Input
5
23 43 123 54 2
3
1 3
2 3
1 2
Output
189
Explanation
In the above example, we have five volunteer [1, 2, 3, 4, 5] who have collected [23, 43, 123, 54, 2] respectively.
We have three groups that consists of [1, 2, 3], [4], [5]. First group collects 189 units of money, second group collects 54 units of money and third group collects 2 units of money. The maximum funds collected by any group is 189. Hence, the output is 189
Example 2
Input
9
34 54 65 76 88 23 56 76 43
7
1 3
2 3
1 2
6 8
5 4
5 7
8 9
Output
220
Explanation
In the above example, we have three groups that consists of [1, 2, 3], [4, 5, 7], [6, 8, 9]. Each group collects 153, 220, 142 units of money respectively. The maximum funds collected by a group is 220. Hence the output is 220.
My Solution->
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,p,a,b,ans=0,i=0;
cin>>n;
vector<long long >v(n);
unordered_map<long long,long long>mp;
for(i=0;i<n;i++){
long long x;
cin>>x;
v[i]=x;
mp[i]=v[i];
ans=max(mp[i],ans);
}
cin>>p;
i=0;
for(i=0;i<p;i++){
cin>>a>>b;
mp[a-1]+=v[b-1];
ans=max(mp[a-1],ans);
mp[b-1]+=v[a-1];
ans=max(mp[b-1],ans);
}
cout<<ans<<endl;
return 0;
}