๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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>
using namespace std;
int countBalancedSubarrays(const vector<int>& arr, int x) {
    int n = arr.size();
    vector<int> prefixSum(n + 1, 0);
    int count = 0;
    for (int i = 0; i < n; ++i) {
        prefixSum[i + 1] = prefixSum[i] + arr[i];
    }
    for (int i = 0; i < x; ++i) {
        for (int j = i; j < x; ++j) {
            int subarraySum = prefixSum[j + 1] - prefixSum[i];
            int subarrayLength = j - i + 1;

            if (subarraySum == subarrayLength) {
                count++;
            }
        }
    }

    return count;
}

int main() {
    int t;
    cin >> t;

    for (int i = 0; i < t; ++i) {
        int n, q;
        cin >> n >> q;

        vector<int> arr(n);
        for (int j = 0; j < n; ++j) {
            cin >> arr[j];
        }

        for (int j = 0; j < q; ++j) {
            int x;
            cin >> x;

            int result = countBalancedSubarrays(arr, x);
            cout << result << endl;
        }
    }

    return 0;
}

ICPC Balance Subarray โœ…
from collections import deque

def bfs(graph, source, dest):
    queue = deque([(source, 0)])
    while queue:
        node, dist = queue.popleft()
        if node == dest:
            return dist
        for neighbor in graph[node]:
            if neighbor != node:
                queue.append((neighbor, dist + 1))
    return -1

def solve():
    t = int(input())
    for _ in range(t):
        n = int(input())
        a, b, c = map(int, input().split())
        graph = {}
        for _ in range(n - 1):
            x, y = map(int, input().split())
            if x not in graph:
                graph[x] = []
            if y not in graph:
                graph[y] = []
            graph[x].append(y)
            graph[y].append(x)

        atoc = bfs(graph, a, c)
        btoc = bfs(graph, b, c)
        atob = bfs(graph, a, b)

        if atoc < btoc:
            print("A")
        elif atob < atoc:
            print("B")
        elif btoc < atoc:
            print("C")
        else:
            print("DRAW")

if name == "main":
    solve()


Three Person โœ… ICPC
#include<bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> cust;
    for(int i = 0; i < n; i++) {
        int q, p;
        cin >> q >> p;
        cust.push_back({p, q});
    }

    vector<vector<int>> rice;
    for(int i = 0; i < m; i++) {
        int q, p;
        cin >> q >> p;
        rice.push_back({p, q});
    }

    sort(cust.begin(), cust.end());
    sort(rice.begin(), rice.end());

    vector<int> x(m, 0);
    int ans = 0;

    for(int i = 0; i < n; i++) {
        int quantity = -1;
        int index = -1;
        for(int j = 0; j < m; j++) {
            if (!x[j]) {
                if (rice[j][0] > cust[i][0]) break;

                if (rice[j][1] > cust[i][1]) {
                    if (quantity == -1) {
                        quantity = rice[j][1];
                        index = j;
                    } else {
                        if (quantity > rice[j][1]) {
                            index = j;
                            quantity = rice[j][1];
                        }
                    }
                }
            }
        }

        if (index != -1) {
            x[index] = 1;
            ans++;
        }
    }

    cout << ans;
}

Super market Codevita โœ…
#include <stdio.h>

int cd=0,ca=0;
void bd(int array[], int n) {
  for (int step = 0; step < n - 1; ++step) {
    for (int i = 0; i < n - step - 1; ++i) {
      if (array[i] < array[i + 1]) {
        int temp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = temp;
        cd++;
      }
    }
  }
}

void ba(int array[], int n) {
  for (int step = 0; step < n - 1; ++step) {
    for (int i = 0; i < n - step - 1; ++i) {
      if (array[i] > array[i + 1]) {
        int temp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = temp;
        ca++;
      }
    }
  }
}

int main() {
    int n;
    scanf("%d",&n);
    int da[n],dd[n];
    for(int i=0;i<n;i++){
        scanf("%d",&da[i]);
        dd[i]=da[i];
    }
    ba(dd, n);
    bd(da, n);
    if(cd>ca)
      printf("%d",ca);
    else
      printf("%d",cd);
}

Best Bubble Codevita โœ…
๐Ÿ‘2