1283E - New Year Parties - CodeForces Solution


dp greedy *1800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define AM17 ios_base::sync_with_stdio(false),cin.tie(NULL);
#define yes cout<<"YES\n";
#define no cout<<"NO\n";

#define lenSorts(s) sort(s.begin(), s.end(), [&] (const string &s, const string &t) { return s.size() < t.size();});
int dx4[4] = { -1, 0, 1, 0 };
int dy4[4] = { 0, 1, 0, -1 };
int dx8[] = {+0, +0, -1, +1, +1, +1, -1, -1};
int dy8[] = {-1, +1, +0, +0, +1, -1, +1, -1};
string Dir = "URDL";
template <class T>
istream & operator>> (istream&is , vector<T> &v )
{
    for (auto &i:v)
        is>> i ;
    return is ;
}
template <class T>
ostream & operator<< (ostream&os ,const vector<T> &v )
{
    for (auto &i:v)
        os << i << " " ;
    os << '\n' ;
    return os ;
}
ll MOD;
ll fastpow(ll a,ll p)
{
    if(p==0)
        return 1ll;

    if(p&1)
        return ((a%MOD) * fastpow(a,p-1))%MOD;
    else
    {
        ll ret=(fastpow(a,p/2));
        return ((ret%MOD) * (ret%MOD))%MOD;
    }
}
//
////ll w[N];
const int N=2e5+10;

//int parent[N];
//struct DSU{
////    vector<ll>cost;
////    ll mx=0;
//    DSU(int n)
//    {
////        sz.resize(N);
//        for (int i = 0; i <= n ; ++i) {
//            parent[i]=i;
////            sz[i]=1;
//        }
//    }
//    int find(int node)
//    {
//        return parent[node];
////        if(parent[node]==node)
////            return parent[node];
////        return parent[node]= find(parent[node]);
//    }
//    bool add(int a,int b)
//    {
////        a= find(a);
////        b= find(b);
////        if(a==b)
////            return false;
////        if(sz[a]<sz[b])
////        { swap(a,b);}
////        parent[b]=a;
////        sz[a]+=sz[b];
//        parent[a]=parent[b];
//        return true;
//    }
//};
//
int main()
{
    int loop=1;
//    cin>>loop;
    while (loop--)
    {
        int n;
        cin>>n;
        vector<int>v(n);
        cin>>v;
        vector<bool>vis(2e5+5, false);
        int mn=0,mx=1;
        sort(v.begin(),v.end());

        for (int i = 0; i < n; ++i) {
            for (int j = -1; j <2 ; ++j) {
                if(!vis[v[i]+j])
                {
                    vis[v[i]+j]=true;
                    mn++;
                    break;
                }
            }
        }
        for (int i = 1; i < n; ++i) {
            if(v[i]-v[i-1]<=2)
            {v[i]=v[i-1];continue;}

            mx++;
        }
        cout<<mx<<" "<<mn<<endl;


    }
}


Comments

Submit
0 Comments
More Questions

1271A - Suits
259B - Little Elephant and Magic Square
1389A - LCM Problem
778A - String Game
1382A - Common Subsequence
1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection
2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes
371A - K-Periodic Array
1542A - Odd Set
1567B - MEXor Mixup
669A - Little Artem and Presents
691B - s-palindrome