160C - Find Pair - CodeForces Solution


implementation math sortings *1700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fast cin.tie(0) , cin.sync_with_stdio(0)
#define clr(arr,val) memset((arr),(val),sizeof(arr))
#define oset(x) tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update> //less_equal
#define endl "\n"
#define read(arr , n) for(int i=0;i<n;i++)cin>>arr[i];
#define ll long long
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define vvl vector<vl>
#define pll pair<ll,ll>
#define f first
#define s second
#define MOD 1000000007
#define mul(x , y , m) ((x%m) * (y%m))%m


const double PI = 2*acos(0.0);
const ll INF = (ll)1e15;
const ll N = (ll)1e5 + 5, M = (ll)1e3;


ll dx[] = {0 , 1 , 0 , -1};
ll dy[] = {1 , 0 , -1 , 0};

ll dxx[] = {-1 ,-1 , 0 , 1 , 1 , 1 , 0 , -1};
ll dyy[] = { 0 , 1 , 1 , 1 , 0 ,-1 ,-1 , -1};



void solve(int tt )
{
    ll n,k; cin>>n>>k;
    map<ll , ll>mp;
    for(int i=0 ; i<n ; i++)
    {
        ll x; cin>>x;
        mp[x]++;
    }

    ll sum = 0;
    for(auto i : mp)sum += i.s;

    for(auto & it : mp)
    {
        if(k <= it.s * sum)
        {
            cout<<it.f<<" ";
            for(auto jt : mp)
            {
                if(k <= jt.s * it.s)return void(cout<<jt.f);
                k -= jt.s * it.s;
            }
        }
        k -= sum * it.s;
    }




}



int main()
{

    fast;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);


    int t = 1 , tt = 0;
    //cin>>t;
    while(t--)solve(++tt);

    return 0;

}


Comments

Submit
0 Comments
More Questions

1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges
WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array