๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.58K photos
3 videos
95 files
9.92K 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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
vector<int> tree[MAX_N];
vector<int> houses[MAX_N];
int A[MAX_N];
int parent[MAX_N];
void dfs(int node) {
    houses[node].push_back(A[node]);
    for (int child : tree[node]) {
        if (child == parent[node]) continue;
        parent[child] = node;
        dfs(child);
        houses[node].insert(houses[node].end(), houses[child].begin(), houses[child].end());
    }
    sort(houses[node].begin(), houses[node].end());
}

int getMaxD(int X, int K, vector<int>& housesInSubtree) {
    int low = 0, high = 1000000000, bestD = 0;
    while (low <= high) {
        int mid = (low + high) / 2;
        int count = 0;
        int left = X - mid, right = X + mid;
        auto lower = lower_bound(housesInSubtree.begin(), housesInSubtree.end(), left);
        auto upper = upper_bound(housesInSubtree.begin(), housesInSubtree.end(), right);
        count = upper - lower;
       
        if (count <= K) {
            bestD = mid;
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
   
    return bestD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }
    for (int i = 1; i < N; ++i) {
        int u, v;
        cin >> u >> v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    parent[1] = -1;
    dfs(1);

    int result = 0;
    while (Q--) {
        int U, X, K;
        cin >> U >> X >> K;
        int d = getMaxD(X, K, houses[U]);
        result ^= d;
    }
    cout << result << endl;

    return 0;
}


Bad Guy โœ…
int findmaximumPackages(vector<int>&arr)
{
    int n = arr.size();
    int mx = *max_element(arr.begin(), arr.end());
    mx = mx * 2;
    int res = 0;
    map<int, int>mp;
    for (auto it : arr) {
        mp[it]++;
    }
    for (int i = 1; i <= mx; i++) {
        int sm = 0;
        for (int j = 1; j <= (i - 1) / 2; j++) {
            sm += min(mp[j], mp[i - j]);
        }
        if (i % 2 == 0) {
            sm += (mp[i / 2] / 2);
        }
        res = max(res, mp[i] + sm);
    }
    return res;
}

Amazon โœ…
public static long getMaxXor(long n) {
    if (n == 0) {
        return 0;
    }
    int x = 0;
    while (n >> x > 0) {
        x++;
    }
    return (1L << x) - 2;
    
   }

IBMโœ