๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.62K subscribers
5.59K photos
3 videos
95 files
10.2K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
#include <iostream>
#include <vector>
#include <functional>
#include <array>

using namespace std;

using ll = long long;
ll maxValue(ll a, ll b) {
    return (a > b) ? a : b;
}

int getMinServers(int n, vector<int> f, vector<int> t, vector<int> w, vector<int> v) {
    vector<ll> size(n), maxDistance(n);
    vector<vector<array<ll, 2>>> adjacencyList(n);

    for (ll i = 0; i < f.size(); i++) {
        f[i]--;
        t[i]--;
        adjacencyList[f[i]].push_back({t[i], w[i]});
        adjacencyList[t[i]].push_back({f[i], w[i]});
    }

    ll answer = 0;

    function<void(ll, ll)> dfs1 = [&](ll u, ll parent) {
        size[u] = 1;
        ll idx = 0;
        while (idx < adjacencyList[u].size()) {
            ll vertex = adjacencyList[u][idx][0];
            ll weight = adjacencyList[u][idx][1];
            if (vertex != parent) {
                maxDistance[vertex] = maxValue(maxDistance[u] + weight, weight);
                dfs1(vertex, u);
                size[u] += size[vertex];
            }
            idx++;
        }
    };

    function<void(ll, ll)> dfs2 = [&](ll u, ll parent) {
        if (u != 0 && maxDistance[u] > v[u]) {
            answer += size[u];
        } else {
            ll idx = 0;
            while (idx < adjacencyList[u].size()) {
                ll vertex = adjacencyList[u][idx][0];
                if (vertex != parent) {
                    dfs2(vertex, u);
                }
                idx++;
            }
        }
    };

    dfs1(0, -1);
    dfs2(0, -1);

    return answer;
}


Cisco โœ…
Minserver
๐Ÿ‘3
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int solve(int i, vector<int>& lst, int ad, const vector<int>& machineCount, const vector<int>& finalMachineCount, int shiftingCost) {
    int n = machineCount.size();
    if (i == n) {
        int res = ad;
        for (int k = 0; k < 3; ++k) {
            res += abs(lst[k] - finalMachineCount[k]);
        }
        return res;
    }
   
    int res = INT_MAX;
    res = min(res, solve(i + 1, lst, ad, machineCount, finalMachineCount, shiftingCost));
   
    for (int j = 0; j < 3; ++j) {
        lst[j] += machineCount[i];
        if (lst[j] - machineCount[i] != 0) {
            res = min(res, solve(i + 1, lst, ad + shiftingCost, machineCount, finalMachineCount, shiftingCost));
        } else {
            res = min(res, solve(i + 1, lst, ad, machineCount, finalMachineCount, shiftingCost));
        }
        lst[j] -= machineCount[i];
    }
   
    return res;
}

int getMinimumCost(const vector<int>& machineCount, const vector<int>& finalMachineCount, int shiftingCost) {
    vector<int> lst(3, 0);
    return solve(0, lst, 0, machineCount, finalMachineCount, shiftingCost);
}

GetMinimum Costโœ…
Cisco
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int SS(const string& rollNumber) {
    int num = 0;
    for (char c : rollNumber) {
        if (isdigit(c)) {
            num = num * 10 + (c - '0');
        }
    }
    return num;
}
bool compare(const pair<string, int>& a, const pair<string, int>& b) {
    string classA = "", classB = "";
    int numA = SS(a.first);
    int numB = SS(b.first);
   
    for (char c : a.first) {
        if (isalpha(c)) classA += c;
        else break;
    }
   
    for (char c : b.first) {
        if (isalpha(c)) classB += c;
        else break;
    }

    if (classA == classB) return numA < numB;
    return classA < classB;
}
int main() {
    int N;
    cin >> N;
    vector<pair<string, int>> students(N);
    for (int i = 0; i < N; ++i) {
        cin >> students[i].first >> students[i].second;
    }
    sort(students.begin(), students.end(), compare);
    for (const auto& student : students) {
        cout << student.first << " " << student.second << endl;
    }
   
    return 0;
}

CBX(intern)โœ…
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool canRobAll(const vector<int>& houses, int H, int K) {
    int hours_needed = 0;
    for (int house_count : houses) {
        hours_needed += (house_count + K - 1) / K; // Ceiling division
    }
    return hours_needed <= H;
}

int main() {
    int N, H;
    cin >> N >> H;
   
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
   
    int left = 1;
    int right = *max_element(A.begin(), A.end());
   
    while (left < right) {
        int mid = left + (right - left) / 2;
        if (canRobAll(A, H, mid)) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
   
    cout << left << endl;
   
    return 0;
}

//Richies World
Flipkartโœ…
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main()
{
    int N, K;
    cin >> N >> K;

    if (N == 0)
    {
        cout << -1 << endl;
        return 0;
    }

    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }

    vector<int> b;
    for (int i = 0; i < N; i++)
    {
        if (isPrime(i + 1) && a[i] >= K)
        {
            b.push_back(a[i]);
        }
    }

    int required = ceil(N / 3.0);

    if (b.size() < required)
    {
        cout << -1 << endl;
        return 0;
    }

    int ans = 0, count = N / 2, t = 0;
    for (int i = 1; i <= N; i++)
    {
        if (a[i - 1] >= K and isPrime(i))
        {
            ans += a[i - 1] / 2;
            count--;

            if (i == 2)
                t = 1;
            if (i == 3 and t == 1)
            {
                count++;
                ans -= a[i - 1] / 2;
            }
        }
        if (count == 0)
            break;
    }
    cout << ans << endl;

    return 0;
}

juice
flipkart โœ…
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    int sumA = 0, sumB = 0;
    for (auto &i : a)
        cin >> i, sumA += i;
    for (auto &i : b)
        cin >> i, sumB += i;

    int ans = min(sumA, sumB), mask = (1 << n);
    for (int i = 0; i < mask; ++i)
    {
        int curr = 0, currentB = 0;
        for (int j = 0; j < n; ++j)
        {
            if (i & (1 << j))
            {
                curr += a[j];
            }
            else
            {
                currentB += b[j];
            }
        }
        ans = max(ans, min(curr, currentB));
    }
    cout << ans << endl;

    return 0;
}
// game
flipkart โœ