Vector Wrong Solution

PROBLEM

#include <bits/stdc++.h>
using namespace std;
/*
T cases
EACH CASE:
N--> workers
w1, w2, w3, w4... salaries of workers
*/
int main(){
    int T,nw,salary;
    T = 0;
    nw = 0;
    salary = 0;
    cin>>T;
    for(int i = 0; i<T;++i)
    {
        cin>>nw;
        vector<int> v;
        vector<int> res;
        for(int j = 0;j<nw;++j)
        {
            cin>>salary;
            v.push_back(salary);
        }
        int maxe = *max_element(v.begin(),v.end());
        for(int l:v){
            res.push_back(maxe-l);
        }
        //int steps=1;
        int val = accumulate(res.begin(),res.end(),0);
        cout<<val<<"\n";


    }
}

I tried to solve this great problem in this way and it shows correct ans in mentioned example But i guess there is some mistake in this method can anyone help me!

THANKS

PLEASE?

Try this test case.

Input

2
7
8 6 4 6 7 3 10 
2
3 8 

Expected Output

23
5

Your Output

26
5

If the above is hard to work on, here’s a smaller test case.

Input

1
5
9 6 2 9 5 

Expected Output

21

Your Output

14
1 Like

Thanks Sure

Actually My output is correct of this ( i think) it should be 14

1
5
9 6 2 9 5

If you’re sure about it, then why are the following AC submissions outputting 21 for that test case?

https://www.codechef.com/viewsolution/54361060
https://www.codechef.com/viewsolution/54295850

2 Likes

THINKING

Ah sorry , Problem in LOGIC thanks a LOTTTT!

1 Like