A tough TCS Codevita 2020?

Are they correct and successfully passing all the test cases? As you know tcs is not that much good with the problem descriptions and their online compiler is also epic.

1 Like

the solutions that will be posted will have passed tcs online judge, its not posted yet, it will be added soon

what logic do you use for calculating nCr when 1<=n<=10^14.
???

Can You please share Logic of Minimize sum

This is My code what is wrong with this code ???
****** Minimum Sum *****

#include
#include<bits/stdc++.h>

using namespace std;

int minSum(vector& a, int k) {
priority_queue<int,vector> pq(a.begin(),a.end());
while(k–)
{
int p = pq.top();
pq.pop();
pq.push(p/2);
}

    int sum = 0;
    while(!pq.empty())
    {
        sum += pq.top();
        pq.pop();
    }
    return sum;
}

int main()
{
int n, k,arr;
cin>>n>>k;
vector v1;
for (int i=0;i<n;i++)
{
cin>>arr;
v1.push_back(arr);
}
int result=minSum(v1, k);
cout<<result;
return 0;
}

while(k--) not while(k–)

(double hyphen not single)

Its K-- code not paste correctly

1 Like

Is getting Presentation error less superior than AC? as I have solved 2 problems both with presentation error!

1 Like

presentation error means Its AC , dont worry, its given in their site somewhere, i came across once. It is considered as AC.

2 Likes

You have to maintain a priority queue for accessing the largest element in O(1) time. So initially, we have to enter all the integers in the priority queue. Now, we can minimize the sum to the least only by performing the operation (floor(x/2)) on the largest interger. So in each opeation, we first store the largest integer in a variable and pop the top interger. Then divide the variable by 2 and push the updated value back in the priority queue. Perform this operation K times. At last, pop the elements and get their minimized sum. (Overall complexity : O(nlogn)

And one more important thing…the sum should be stored in a long long int type variable otherwise it gives WA.

1 Like

No…they both are the same… nothing superior or inferior.

2 Likes

not necessarily … they can call u for interview even if u solve 1 question … depends on submission stats overall

OK , jesa theek lage :slight_smile:

In my set there was a problem “Count Pairs”, Has any one done that?
Rest were Minimize Sum(done), Constellations(done), Hedger was 01 knapsack problem on submitting it showed memory limit exceeded or TLE.

Mine as well.

I think this solution will also got accepted for minimize the sum

code

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
fastio;
ll n,s=0,i,k;
cin>>n>>k;
ll a[n];
for(i=0;i<n;i++)
cin>>a[i];

sort(a,a+n,greater<int>());
 i=0;
while(k--)
{
    if(a[i]>a[i+1])
    a[i]=a[i]/2;
    else
    {
        i++;
        a[i]=a[i]/2;
    }
}
for(i=0;i<n;i++)
s+=a[i];
cout<<s<<endl;

}

Do any of you know how many question sto solve for qualifying for second round

Do you have correct solution for the problem Hedger then it would be very kind of you if you share it.

Guys wanting questions can visit here

1 Like

As i said Hedger showed MLE when using efficient approach probably because range of W was in 10^6 if you would like to know then go through problem after reading 01 knapsack.