description
stringlengths
35
9.39k
solution
stringlengths
7
465k
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; struct num { long long l, r; } a[200005]; bool cmp(num x, num y) { if (x.l == y.l) return x.r > y.r; return x.l > y.l; } long long n, s; long long check(long long m) { long long br = n / 2 + 1, sum = 0; for (int i = 0; i < n; i++) { if (a[i].l <= m && m <= a[i...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; long long n, s, INI; pair<long long, long long> a[200010]; bool op(long long meta) { long long quant = 0, disponivel = s; for (long long i = n; i >= 1; i--) { long long vez = meta - a[i].first; if (a[i].first >= meta) { quant++; continue; } i...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
from sys import stdin, stdout def fun1(n,m,l,s): cl=0 cr=0 cm=0 for i in range(n): if l[i][1]<m: s-=l[i][0] cl+=1 elif l[i][0]>m: s-=l[i][0] cr+=1 else: cm+=1 if (cm+cr)<=1+n//2: s-=m ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200020; inline long long read() { char ch = getchar(); long long x = 0, f = 0; while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return f ? -x : x; } struct seg { i...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys input=sys.stdin.readline t=int(input()) def ok(mid,l,n,s): su=0 cnt=0 ll=[] for i in range(n): if(l[i][1]<mid): su+=l[i][0] elif(l[i][0]>=mid): su+=l[i][0] cnt+=1 else: ll.append(l[i]) ll.sort() ne=max(0,(n+1)//2-...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; const int M = 1e9 + 7; vector<pair<int, int> > seg; bool check(long long n, long long s, long long median) { long long less = 0, more = 0; long long cur = 0; vector<int> v; for (int i = 0; i < n; i++) { if (seg[i].second < median) { ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int mod = 1e9 + 7; const int maxn = 2e6 + 100; const int maxm = 2e6 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); int t; pair<long long, long long> a[maxn]; long long s; int n; int vis[maxn]; bool cmp2(pair<long long, long l...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; int n; long long s; pair<int, int> a[200010]; bool take[200010]; bool good(int x) { int cnt = n / 2; long long tot = 0; for (int i = 1; i <= n; i++) { if (a[i].second < x) { tot += a[i].first; --cnt; take[i] = true; } else take[i] = fal...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys input1 = sys.stdin.readline def solve(): n, s = [int(i) for i in input1().split()] empl = [[] for i in range(n)] for i in range(n): empl[i] = [int(j) for j in input1().split()] empl.sort(reverse=True) lg = 0 rg = 10 ** 9 + 1 while rg - lg > 1: mg = (rg + lg) // ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; struct node { long long l, r; }; bool cmp(node a, node b) { if (a.l != b.l) return a.l < b.l; return a.r < b.r; } long long T, N, S; node a[200005]; bool can(long long x) { long long cnt = 0; long long money = 0; for (long long i = N; i >= 1; i--) { if (a[i]...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOExcept...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const double PI = acos(-1); long long mod = 1e9 + 7; struct segment { long long l, r; bool operator<(const segment& s) const { return l < s.l; } }; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; long long n, s, t, cnt, sum; const int maxn = 2e5 + 7; pair<long long, long long> a[maxn]; int main() { cin >> t; while (t--) { cin >> n >> s; for (int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; } sort(a + 1, a + n + 1); long long ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys input = sys.stdin.readline import heapq as hq t = int(input()) for _ in range(t): n,s = map(int,input().split()) sr = [list(map(int,input().split())) for i in range(n)] summn = sum(list(zip(*sr))[0]) med = n//2+1 l = 0 r = s+1 while l+1<r: flg = 0 x = (l+r)//2 cost = summn q = [...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Random; import java.util.StringTokenizer; publi...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import os def binary_search(f, low, high): mid = (high + low) // 2 if low == high: return low if f(mid): return binary_search(f, mid + 1, high) else: return binary_search(f, low, mid) # for i in range(10): # f = lambda x: x <= i # assert binary_search(f, 0, 100) == i...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; int const N = 200000, inf = 1e9; pair<int, int> x[N]; int n; vector<int> y; bool ok(int m, long long s) { y.clear(); for (int i = 0; i < (int)(n); ++i) { s -= x[i].first; if (m <= x[i].second) { if (m >= x[i].first) y.push_back(m - x[i].first); ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> f; long long n, s; bool can(long long mid) { long long sum = 0, cnt = 0; vector<long long> v; for (long long i = 0; i < n; i++) { if (f[i].second < mid) sum += f[i].first; else if (f[i].first >= mid) { sum += f[i]...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; struct range { int l, r, id; } rng[200010]; int vis[200010]; int n; long long s; bool find(int m) { for (int i = 1; i <= n; i++) vis[i] = 0; int lcnt(0), rcnt(0); long long sum(0); for (int i = 1; i <= n; i++) { if (rng[i].r < m) { lcnt++; sum += r...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys input = sys.stdin.readline def judge(x): salary = 0 left_cnt, right_cnt = 0, 0 arr = [] for li, ri in lr: if ri<x: salary += li left_cnt += 1 elif x<li: salary += li right_cnt += 1 else: arr.append(li) ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; bool check(long long mid, int cnt, long long total) { int i, c = 0, c1 = 0; long long sum = 0; vector<long long> tmp; for (i = 0; i < v.size(); i++) { if (v[i].second < mid) sum += v[i].first; else if (mid <= v[i].first) { ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
/** * BaZ :D */ import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { static MyScanner scan; static PrintWriter pw; static long MOD = 1_000_000_007; static long INF = 1_000_000_000_000_000_000L; static long inf = 2_000_000_000; public static void main(Strin...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.PriorityQueue; import java.util.StringTokenizer; public class D { static int N; static long S; static long[] l,r; public static void main(String[]...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; int amount; long long total; pair<int, int> salary[1000005]; bool is_good(int median_sal) { int need = (amount + 1) / 2; long long total_need = 0; for (int i = amount; i >= 1; i--) if (salary[i].first >= median_sal) { need--; total_need += salary[i].fi...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; public class CodingLegacy { public static void main(String[] args) { InputStream inputStream = System.in; ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; long long l[500005], r[500005], n, s; bool check(long long x) { long long k = n + 1 >> 1; vector<long long> vec; for (long long i = 1, v; i <= n; i++) { v = max(l[i], x); if (r[i] < v) continue; vec.push_back(v - l[i]); } if (vec.size() < k) return 0; ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; struct Node { int L, R; bool operator<(const Node &other) const { return L < other.L; } }; int N, H; long long S; vector<Node> v; bool possible(int median) { long long sum = 0; for (Node &s : v) sum += s.L; int count = 0; for (int i = N ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.*; import java.util.*; public class CF1251D extends PrintWriter { CF1251D() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1251D o = new CF1251D(); o.main(); o.flush(); } static class V { int l, r; V(int l, int r) { this.l = l; this.r =...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> t; while (t--) { long long s; cin >> n >> s; vector<int> l(n), r(n); for (i = 0; i < n; i++) { cin >> l[i] >> r[i]; } vector<int> ord(n); iota(...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const long long mx = 200005; bool comparator(pair<long long, long long> A, pair<long long, long long> B) { return A.first < B.first; } int main() { ios::sync_with_stdio(0); long long q; cin >> q; while (q--) { long long n, s; long long l; long long r; ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
if __name__ == '__main__': import sys input = sys.stdin.readline test = int(input()) for i in range(test): numbers = list(map(int, input().split())) people = numbers[0] # the nr of people is odd salary = numbers[1] interv= [] nr = 0 for j in range(...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const long long N = 2e5 + 10; long long T, n, s, mx, ts; struct node { long long l, r; } t[N]; long long cmp(node a, node b) { return a.l < b.l; } inline long long check(long long mid) { long long cnt = 0; s = ts; for (long long i = n; i >= 1...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.*; import java.util.*; import java.text.*; import java.lang.*; import java.math.*; public class Main{ // static ArrayList a[] = new ArrayList[500006]; static int n; static long a[][]; static long tot; static boolean f(long mid) { int cnt = 0; Vector<Long>v = new Vector<>()...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.util.*; public class Main { static long binarySearch(long a, long b, long s, long[] low, long[] high) { if (a == b) return a; long mid = (a + b + 1) / 2; if (works(mid, s, low, high)) return binarySearch(mid, b, s, low, high); else return binarySearch(a, mid - 1, s,...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; int t; int n; long long s; struct salary { long long l, r; }; salary a[200001]; bool cmp(salary a, salary b) { return a.l > b.l; } void nhap() { scanf("%d%lld", &n, &s); for (int i = 1; i <= n; i++) { scanf("%lld%lld", &a[i].l, &a[i].r); } sort(a + 1, a + n + ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; long long read() { char x = getchar(); long long ans = 0, flag = 1; while (!isdigit(x)) if (x == '-') flag = -1, x = getchar(); else x = getchar(); while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar(); return ans * flag; } long long n, s;...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > d; long long s; int f(int cost) { int cnt = 0; long long sum = 0; vector<int> vec; for (int i = 0; i < (int)d.size(); i++) if (cost <= d[i].first) { cnt++; sum += d[i].first; } else if (d[i].second < cost) sum += d[i...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.*; import java.util.*; import java.lang.*; import java.math.*; public class Main extends Thread { boolean[] prime; FastScanner sc; PrintWriter pw; long startTime = System.currentTimeMillis(); final class FastScanner { BufferedReader br; StringTokenizer st; p...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys import math from collections import defaultdict from itertools import combinations from itertools import permutations input = lambda : sys.stdin.readline().rstrip() read = lambda : map(int, input().split()) def write(*args, sep="\n"): for i in args: sys.stdout.write("{}".format(i) + sep) INF = float('i...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys input = sys.stdin.readline import heapq sys.setrecursionlimit(100000) def getN(): return int(input()) def getList(): return list(map(int, input().split())) def solve(): ls, rs = [], [] n, money = getList() sals = [] for _ in range(n): a, b = getList() sals.append((a, ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author be...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > v; vector<long long int> v1; long long n, s, lef; bool check(long long x) { long long t = lower_bound((v1).begin(), (v1).end(), x) - v1.begin(); if (t <= n / 2) return 1; long long needed = t; long long left = lef; for (...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys,os,io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline for _ in range (int(input())): n,s = [int(i) for i in input().split()] l = [] r = [] v = [] for i in range (n): li,ri = [int(i) for i in input().split()] l.append(li) r.append(ri) v.append(...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; void solve() { int n; LL s; scanf("%d%lld", &n, &s); vector<int> lb(n), ub(n); for (int i = 0; i < n; ++i) scanf("%d%d", &lb[i], &ub[i]); auto check = [&](int mid) -> int { multiset<LL> se; LL tot = 0; ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys import operator input = sys.stdin.buffer.readline def f(med): total = 0 cnt = 0 cnt2 = 0 other = [] for x in salaries: if x[0] > med: total += x[0] # too big pay min salary cnt += 1 elif x[1] < med: total += x[0] # useless so pay min...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; public class Main { public static int maxn=200010,n; public static long s; public static node p[]=new node[maxn]; public static Compar...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n,s=map(int,input().split()) lr=[list(map(int,input().split())) for i in range(n)] ng=10**9+1 ok=0 while ng-ok>1: mid=(ok+ng)//2 cnt_more=0 ss=0 v=[] for l,r in lr: if mid<=l: ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.util.*; import java.io.*; public class EdD { public static void main(String[] args) throws Exception{ int num = 998244353; // TODO Auto-generated method stub BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys readline = sys.stdin.readline inf = 10**16 def calc(m, L, R): N = len(L) cl = 0 cr = 0 ss = 0 candi = [] for i in range(N): if L[i] > m: cr += 1 ss += L[i] elif R[i] < m: cl += 1 ss += L[i] else: can...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { Problems problems = new Problems(); problems.solve(); } } class Problems { Parser parser = new Parser(); void...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.util.Collections; import java.util.ArrayList; import java.io.InputStream; /** * @author khokharnikunj8 */ public class Ma...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys import bisect input=sys.stdin.readline def checker(rem_,lower_): sum_=0 a=[] b=[] for i in range(n): if lower[i][1]>=rem_: a.append(lower[i][0]) else: b.append(lower[i][0]) a.sort(reverse=True) if len(a) > n//2 and sum([max(j, rem_) for j in a[:...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collection; import java.util.InputMismatchException; import java.io.IOException; import java.util.Random; import java.util.Comparator; import java.util.NoSuchElement...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import sys input = sys.stdin.readline def solve(mid): ans = 0 cnt = 0 tmp = [] for i in range(n): if info[i][1] < mid: ans += info[i][0] elif mid < info[i][0]: ans += info[i][0] cnt += 1 else: tmp.append(info[i][0]) tmp.sor...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.*; import java.math.*; import java.util.*; public class Main { //static final long MOD = 998244353; static final long MOD = 1000000007; static final int INF = 1000000007; static int[][] perms; static int index; public static void main(String[] args) throws IOException { FastScanner sc = ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> long long int paixu(long long int shuzu[][2], long long int daxiao) { long long int i, j, k, l; l = daxiao; if (l >= 1000) { l = 1000; } for (l = l; l >= 1; l /= 2) { for (i = l; i <= daxiao; i++) { for (j = i; ((shuzu[j][1] < shuzu[j - l][1]) & (j > l)); j -= l) { ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; import java.util.StringTokenizer; public class D { public static void main(String[] args) throws Exception { // StringTokenizer stok = new StringTokenizer(new Scanner(new Fil...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; long long mo(const long long input, const long long ceil) { return input >= ceil ? input % ceil : input; } long long n, s, ans, l, r, i, mid, cnt, sum; pair<long long, long long> a[400000]; void solve(long long tt) { cin >> n >> s; for (i = 1; i <= n; i++) { cin >...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; int n; long long s; long long l[200010], r[200010], b[200010]; long long res; bool ok(long long x) { long long tmp = 0; int dem; dem = 0; vector<int> mi; mi.clear(); for (int i = 1; i <= n; i++) { if (r[i] < x) { tmp += l[i]; continue; } ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int man = 2e5 + 10; template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T exgcd(T a, T b, T &g, T &x, T &y) { if (!b) { g = a, x = 1, y = 0; } else { exgcd(b, a % b, g, y, x); y -...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; bool check(pair<long long int, long long int> arr[], long long int mid, long long int n, long long int s) { vector<pair<long long int, long long int>> both; long long int l = 0, r = 0; for (long long int i = 0; i < n; i++) { if (arr[i].second < mid) { ...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import os, sys, atexit from io import BytesIO, StringIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline _OUTPUT_BUFFER = StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) t = int(input()) while t: t += -1 n, s = map(int, i...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
import java.util.*; import java.io.*; public class SalaryChanging { public static void main(String[] args) { FastScanner scanner = new FastScanner(); PrintWriter out = new PrintWriter(System.out,false); int t = scanner.nextInt(); while(t-->0) { int n = scanner.nextInt();...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const long long M = 3 * (1e5) + 7, mod = 1e9 + 7; long long n, s; vector<pair<long long, long long>> v; bool ok(long long mid) { vector<pair<long long, long long>> d; for (auto u : v) { if (u.second >= mid) { d.push_back({u.first, u.second}); } } sort(...
You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i dollars. You have to distribute salaries in such a way that the ...
#include <bits/stdc++.h> using namespace std; const int o = 1 << 17; const int maxn = 200005; const int mod = 1000000007; const int inf = 0x3f3f3f3f; const long long huge = 100000000000000000LL; long long s; int n, t; int l[maxn], r[maxn]; int tmp[maxn]; long long price(int med) { long long ret = 0; int cnt = 0; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=list(input()) s.append("B") b=s.count("B") w=len(s)-b if b==1 or w==0: print(0) exit(0) s.pop(n) b-=1 if b%2 and w%2: print("-1") exit(0) if b%2==0: p=[] for i in range(s.index('B'),n-1): if s[i]=="W": continue if s[i+1:].count('B')==0: ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; bool besarDulu(const int &a, const int &b) { return a > b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s, sOri; cin >> sOri; s = sOri; int B_count = 0, W_count = 0; bool W_ada = false, B_ada = false; for (int i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; char s[200005]; vector<int> ans; int main() { int T = 1; while (T--) { int n; cin >> n; scanf("%s", s + 1); int cnt1 = 0, cnt2 = 0; for (int i = 1; i <= n; i++) s[i] == 'B' ? cnt1++ : cnt2++; if (cnt1 % 2 && cnt2 % 2) { puts("-1"); co...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
""" Satwik_Tiwari ;) . 5th AUGUST , 2020 - WEDNESDAY """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesI...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import sys def flip(c, i): if c[i] == 'W': c[i] = 'B' else: c[i] = 'W' n = int(input()) c = list(input()) ops = [] for i in range(1, n - 1): if c[i - 1] != c[i]: flip(c, i) flip(c, i + 1) ops.append(i + 1) if c[n - 1] != c[n - 2]: if n % 2 == 0: prin...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int c1 = 0, c2 = 0; vector<bool> a(n); for (int i = 0; i < n; i++) { char tmp; cin >> tmp; if (tmp == 'B') { c1++; a[i] = 0; } else { c2++; a[i] = 1; } } if (c1 % 2 == 1 && c2 % 2 == 1...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
'''input 1 B ''' from sys import stdin import math def input(): return stdin.readline()[:-1] n = int(input()) l = list(input()) l2 = l[:] if n == 1: print(-1) else: # all white to black i = 0 pos = [] while i < n - 1: if l[i] == 'W' and l[i + 1] == 'W': pos.append(i+1) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
# map(int, input().split()) # list(map(int, input().split())) def pairup(col,i): if i >= n: return 0 if blocks[i] != col: pairup(col,i+1) elif blocks[i] != blocks[i+1]: # should not give index error blocks[i], blocks[i+1] = blocks[i+1], blocks[i] seq.append(i+1) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) s = list(input()) ans = [] f = "W" if s.count("B")%2 == 0 else "B" for i in range(0,len(s) - 1): if(s[i] != f): ans.append(i+1) s[i] = f if(s[i + 1] == "W"): s[i + 1] = "B" else: s[i + 1] = "W" if(s[len(s) - 1] == f): if(len(ans)>0): print(len(ans)) print(*ans) else: print(...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
# from debug import debug import sys from math import ceil input = sys.stdin.readline n = int(input()) s = [True if x == 'W' else False for x in input().strip()] r = s[:] store = [] for i in range(n-1): if s[i]: continue else: store.append(i+1); s[i] = not s[i]; s[i+1] = not s[i+1] if s[-1]: print(len(store)) pri...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class codeforces { static int M = 1_000_000_007; static int INF = 2_000_000_000; static final FastScanner fs = new FastScanner(); //variable public static void main(String[] a...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int b = 0, c = 0; int k = 0; int n; void solve(void) { cin >> n; string x; cin >> x; vector<int> indexB; vector<int> indexW; for (int i = 0; i < n; i++) { if (x[i] == 'B') { b++; indexB.push_back(i + 1); } else { c++; indexW.push_...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int count_b = 0, count_w = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') count_w++; else count_b++; } if (count_b % 2 != 0 && count_w % 2 != 0) { cout << -1 << endl; return 0; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) block = list(input()) W=0 B=0 moves = [] for x in block: if x == 'W': W += 1 else: B += 1 status = 0 if W%2 == 1 and B%2 ==1: print(-1) status = -1 else: if W%2 == 0: for i in range(len(block)-1): if block[i] == 'W': if block[i] ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
/* Rajkin Hossain */ import java.io.*; import java.util.*; import static java.lang.Math.*; public class B { FastInput k = new FastInput(System.in); //FastInput k = new FastInput("/home/rajkin/Desktop/input.txt"); FastOutput z = new FastOutput(); char [] y; int n; void startAlgo()...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def convert(arr): return ['1' if i=='0' else '0' for i in arr] def solve2(arr): #since we are changing `0`s, to `1`s answer = [] #first change `0`s in pair i = 0 while i<len(arr)-1: if arr[i]=='0' and arr[i+1]=='0': arr[i] = '1' arr[i+1] = '1' ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) s = input() def function(s): if len(s)%2 == 0: count =0 for elements in s: if elements == "B": count+=1 else: continue if count%2 == 0: array_steps = [] selection = False selected = ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import sys n = int(input()) s = list(input()) s2 = s.copy() ans = [] for i in range(n-1): if s[i] == 'B': ans.append(i+1) if s[i+1] == 'B': s[i+1] = 'W' else: s[i+1] = 'B' if s[n-1] == 'W': print(len(ans)) print(" ".join(map(str, ans))) sys.exit() ans = []...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; vector<int> ans; char s[100001]; int main() { int n; scanf("%d %s", &n, s); for (int i = 0; i < n - 1; ++i) { if (s[i] == 'W') { s[i] = 'B'; s[i + 1] = (s[i + 1] == 'W') ? 'B' : 'W'; ans.push_back(i + 1); } } if (s[n - 1] == 'B') { pr...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) s = list(input()) arr = [] for i in s: if i == 'B': arr.append(1) else: arr.append(0) toMake = arr[0] count = 0 affected = [] for i in range(1, len(arr)-1): if arr[i] != toMake: arr[i] = 1 - arr[i] arr[i+1] = 1 - arr[i+1] affected.append(i+1) count += 1 if arr.count(toMake) == len(arr): ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
from collections import Counter _ =int(input()) s = list(input()) counter = Counter(s) bs, ws = counter['B'], counter['W'] if bs%2!=0 and ws%2!=0: print(-1) else: c = 'W' if ws%2==0 else 'B' ops= [] i = 0 while i <len(s)-1: if s[i] == c: if s[i+1] != c: s[i], s[i+1] = s[i+1], s[i] ops.append(i+1) e...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; import java.io.*; public class B { public static void main(String[] args) { FastScanner sc = new FastScanner(); int n = sc.nextInt(); PrintWriter pw = new PrintWriter(System.out); int[] q = new int[2]; char[] s = sc.next().toCharArray(); int[] in = new int[n]; for(int i = 0; i < n; i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int len,len1,flag=0,sum[]=new int[606],k; int b=0,w=0; k=0; len=sc.nextInt(); char str[]=sc.next().toCharArray(); for(int i=0;i<str.length;i++) { if(str[i]...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; vector<int> v; int numOfBlocks, j; string block; void invert(char s) { for (int i = 0; i < numOfBlocks; i++) { if (block[i] == s) { j = i + 1; while (block[j] != s) { v.push_back(j); block[j - 1] = block[j - 1] == 'B' ? 'W' : 'B'; b...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> int va = 10e8 + 7; long long val[200007] = {0}; using namespace std; long long getmul(long long n) { long long int k{0}; while (n > 0) { k += n % 10; n = n / 10; } return k; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t{1}; while (t--) { int n...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
# ":" n = int(input()) s = input() lis = [i for i in s] # all black che_black = ["B"]*n ans = [] for i in range(n-1): if lis[i] == "W": ans.append(i+1) lis[i] = "B" if lis[i+1] == "W": lis[i+1] = "B" else: lis[i+1] = "W" if lis == che_black: print(len(ans)...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) s = input() from collections import Counter c = Counter(s) if ((c["B"]%2==1 and c["W"] > 0) or (c["B"] > 0 and c["W"]%2==1)) and len(s)%2==0: print(-1) else: s = list(s) scopy = s[:] targ = s[0] d = {"W":"B", "B":"W"} c = 0 ans = [] while len(set(s))!=1: #prin...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def solve1(str,c,d): nw=str[0] ans=[] pos=0 for i in (str[1:]): pos+=1 if(nw==d): ans.append(pos) nw=i if(i==d): nw=c else: nw=d else: nw=i if(nw==c): print(len(ans)) f...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) b=input() a=[] for i in b: a.append(i) wn=a.count('W') bn=a.count('B') if wn==0 or bn==0: print(0) elif wn%2!=0 and bn%2!=0: print(-1) else: c='-' count=0 ans=[] if wn%2==0: c='W' else: c='B' for i in range(n-1): if a[i]==c: if a[i]=...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c, d, e, t, max_cost, ans = 0; string s; string original; cin >> n; if (n == 0) { cout << "0"; return 0; } cin >> s; original = s; int arr[n]; int j = 0, f = 0; for (long long int i = 0; i < n; i++) { arr...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
N = int(input()) S = input() black = [] white = [] for i, s in enumerate(S, 1): if s == "B": black.append(i) elif s == "W": white.append(i) black_num = len(black) white_num = len(white) if black_num == 0 or white_num == 0: print(0) exit() if black_num % 2 == 1 and white_num % 2 == 1:...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; void speed() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long N = 1e5 + 5; const long long NN = 105; const long long MAX = 2e5 + 123; const long long MOD = 1e9 + 7; const long long INF = 1e18; vector<pair<long long, long long> > vb, vw; ...