Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

pranshu_2004's blog

By pranshu_2004, history, 16 months ago, In English

https://codeforces.me/contest/2022/problem/B Can anybody tell me that why my sol is not working for above problem

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int t;
    cin >> t;
    while (t--)
    {
        ll n,x,temp,ans=0;
        cin >> n >> x;
        multiset<ll> s;
        for (int i = 0; i < n; i++)
        {
            cin >> temp;
            s.insert(temp);
        }
        while (s.size()>x)
        {
            vector<ll> p;
            ll j=x,minm=*s.rbegin();
            while (j)
            {
              auto it=s.end();
              it--;
                minm=*it;
                p.push_back(minm);
                s.erase(it);
                j--;
            }
            
            for (int i = 0; i < p.size(); i++)
            {
              if(p[i]-minm!=0)
                s.insert(p[i]-minm);
            }
            ans+=minm;
        }
        if (s.size())
        {
            ans+=*s.rbegin();
        }
        cout << ans << endl;
    }
    return 0;
}

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

By pranshu_2004, history, 16 months ago, In English

Can anybody tell that how your contribution is calculated here , like what is denoted by positive and negative number ?

Full text and comments »

  • Vote: I like it
  • -2
  • Vote: I do not like it