1539C - Stable Groups - CodeForces Solution


greedy sortings *1200

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <string>
#include<stack>
#include<unordered_set>
#include<queue>
#include<deque>
#include<algorithm>
#include <cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<iomanip> // setprecision(number)   cout << fixed << setprecision(6);
#include<ctype.h> //  towlower toupper
#define sa(a,n) sort(a,a+n)
#define endl   "\n"
#define ll long long
#define tt int
#define str string
#define fs(n)              fixed<<setprecision(n)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main() {
    fast;  
     ll n, k, xx;
     cin >> n >> k >> xx;
     vector<ll> v(n);
     for (ll x=0; x<n;x++) 
        cin >> v[x];
     sort(v.begin(),v.end());
    //...........................
    vector<ll> v2;
    ll con1 = 0,con2=0;
    for (ll x=1; x<n;x++) 
    {
        ll j= v[x] - v[x - 1];
        if (j>xx)
        {
            v2.push_back(j);
            con1++;
        }
    }
    sort(v2.begin(),v2.end());
    for (ll x=0; x<v2.size();x++) 
    {
        if(v2[x]%xx==0)//wr6 n=5  k=3 xx=2 .... 9 1 5 1 9
        v2[x]--;
        ll c =v2[x]/xx;
        if(k>=c&&k!=0)
        {
            con2++;
            k-=c;
        }
    }
    cout << ++con1 - con2 ;
     
}


Comments

Submit
0 Comments
More Questions

1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words