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 ...
import java.io.*; import java.util.*; public class MainClass { public static void main(String[] args)throws IOException { Reader in = new Reader(); int t = in.nextInt(); StringBuilder stringBuilder = new StringBuilder(); while (t-- > 0) { int n = in.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 int N = 2e5 + 10; struct node { int l; int r; } a[N]; bool cmp(node a, node b) { if (a.l == b.l) return a.r > b.r; return a.l > b.l; } long long n, s; int check(int x) { int k = n / 2, cnt = 0; long long sum = 0; for (int i = 0; i < n; 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 ...
// package Quarantine; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; import javafx.util.Pair; public class SalaryChanging { public static void main(String[] args)throws IOExce...
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 getmaximummediansalary(lra, n, s): l = 0 h = s while l < h: m = (l + h + 1)//2 #print(m) if candistribute(m, lra, s): l = m else: h = m-1 return l def candistribute(m, lra, s): cntl = 0 cntm = 0 cn...
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 def I(): return sys.stdin.readline().rstrip() for _ in range( int( I() ) ): n, s = map( int, I().split() ) half = n // 2 lows = 0 l, r = [], [] for _ in range( n ): x, y = map( int, I().split() ) lows += x l.append( x ) r.append( y ) money = 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; long long t, n, S, s, up, down, mid, mx, mn, a, b, k, l, r, ans, raod; pair<long long, long long> p[300005]; int main() { cin >> t; while (t--) { cin >> n >> S; mn = 1e10; mx = 0; for (k = 1; k <= n; k++) { cin >> a >> b; p[k].first = 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 ...
#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 ...
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); StringBuilder sb=new StringBuilder(); int t=s.nextInt(); for(int i=0;i<t;i++) { int n=s.nextInt(); long sum=s.nextL...
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 raw_input = stdin.readline pr = stdout.write def fun(x,n,arr,sal): c1,c2=0,0 sm=0 temp=[] for i in xrange(n): if arr[i][1]<x: c1+=1 sm+=arr[i][0] elif arr[i][0]>=x: sm+=arr[i][0] else: temp...
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 takemod(int a, int mod) { a %= mod; if (a < 0) a += mod; return a; } int fast_exp(int base, int expo, int mod) { int res = 1; while (expo > 0) { if (expo & 1) res = (res * base) % mod; base = (base * base) % mod; expo >>= 1; } return res; } int...
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 ...
// Don't place your source in a package import java.lang.reflect.Array; import java.text.DecimalFormat; import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import java.util.stream.Stream; // Please name your class Main public class Main { static FastScanner fs=new FastScanner(); stat...
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; pair<long long, long long> ara[200005]; int n; long long s; bool cheak(long long m) { long long rem = s; for (int i = 0; i < n; i++) rem -= ara[i].first; int p = (n + 1) >> 1; for (int i = 0; i < n && p; i++) { if (ara[i].first >= m) p--; else if (ara[...
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 = 1001001001; const long long LINF = 1e17; const double pi = 3.1415926535897932; const string endstr = "\n"; template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } ...
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 java.io.*; import java.util.*; public class Main { public static void main(String[] args) { new Thread(null, new Runnable() { public void run() { FastReader fr =new FastReader(System.in); PrintWriter op =new PrintWriter(System.out); int T =fr.nextInt() ; while (T-...
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 java.io.*; import java.util.*; public class r75p4 { private static BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer tk; private static PrintWriter pw = new PrintWriter(System.out); private static void next()throws IOException{ if(tk...
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): l, r = info[i] if r < mid: ans += l elif mid < l: ans += l cnt += 1 else: tmp.append(l) tmp.sort(reverse = True) ...
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.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.InputMismatchException; import java.util.List; public class Main { private static final String 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 int a[200010][2]; bool check(long long int m, long long int n, long long int s) { long long int aa = 0, bb = 0; long long int sal = 0; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { if (a[i][1] < m) aa++, sal = sal + a[i][0]; else if...
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 D { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int T = Integer.parseInt(st.nextToken()); for(int t = 0; t < T; t+...
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 = 233333; long long suml = 0, n, s; struct node { int l, r; } e[maxn]; bool cmp(node a, node b) { if (a.l == b.l) return a.r < b.r; return a.l < b.l; } int vis[maxn]; bool check(int x) { long long now = suml; int cnt = 0; for (int i = n; i >= 1; 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.lang.*; import java.io.*; public class Solution { public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t= Integer.parseInt(br.readLine()...
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 ...
#include <bits/stdc++.h> using namespace std; int N, N2; long long S; const int MAXN = 2e5 + 15; pair<long long, long long> A[MAXN]; long long I[MAXN]; bool check(long long m) { int c2 = 0, n = 0; long long sum = 0; for (int i = 0; i < N; ++i) if (A[i].second < m) { sum += A[i].first; } else 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.*; import java.util.*; public class LabAlgoOne { //Scanner static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out)); static String currentInputLine = ""; static String inputFi...
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.*; import java.math.BigInteger; public class tr0 { static PrintWriter out; static StringBuilder sb; static final double EPS = 1e-9; static long mod = (int) 1e9 + 7; static int inf = (int) 1e9 + 2; static long[] fac; static int[] si; static ArrayList<Integer> primes; static 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.*; import java.util.*; public class MainClass { public static void main(String[] args)throws IOException { Reader in = new Reader(); int t = in.nextInt(); StringBuilder stringBuilder = new StringBuilder(); while (t-- > 0) { int n = in.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; int main() { int q; scanf("%d", &q); while (q--) { int n; long long s; scanf("%d %I64d", &n, &s); long long deb = 0, fin = s; int l[n], r[n]; for (int i = 0; i < n; i++) { scanf("%d %d", &l[i], &r[i]); s -= l[i]; } while (de...
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.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class e { public static class FastReader { BufferedReader br; StringTokenizer st; //it reads the data about the specified point and divide the d...
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 = 1e9 + 200ll; bool can(vector<pair<int, int>> a, long long tar, int n, long long s) { int cnt = 0; long long sum = 0ll; vector<int> use; for (int i = 0; i < n; ++i) { if (a[i].second < tar) { sum += (long long)a[i].first; } else if...
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.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class e { public static class FastReader { BufferedReader br; StringTokenizer st; //it reads the data about the specified point and divide the d...
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; pair<long long, long long> a[200010]; long long n, s; bool ok(long long x) { long long cnt = 0, left = s; for (long long i = 0; i < n; i++) left -= a[i].first; for (long long i = 0; i < n; i++) { if (a[i].first >= x) cnt++; else if (a[i].second >= x) { ...
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; vector<pair<long long, long long> > arr; bool can(long long x) { long long ans = 0; vector<pair<long long, long long> > todo; for (long long i = 0; i < n; i++) { if (arr[i].second < x) todo.push_back(arr[i]); } for (long long i = 0; i < n; 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; const int inf = 0x3f3f3f3f; const int N = 2e5 + 10; int n; long long s; struct node { int l, r; bool operator<(const node& a) const { return l < a.l; } } p[N]; vector<int> g; int judge(long long x) { g.clear(); long long sum = 0, cnt1 = 0, cnt2 = 0; for (int 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 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.buffer.readline def check(num): count1 = 0 count2 = 0 spent = 0 left = [] for i in l: if i[0] > num: count2 += 1 spent += i[0] elif i[1] < num: count1 += 1 spent += i[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; struct node { int l, r; friend bool operator<(node a, node b) { return a.l < b.l; } } ee[200005]; int get(int n, int x, long long k) { long long sum = 0; int cnt = n / 2 + 1; for (int i = n; i >= 1; i--) { if (ee[i].l <= x && ee[i].r >= x && cnt) { sum +...
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 MOD = (long long)(1e9 + 7); const long long N = 200007; vector<pair<long long, long long>> v; long long s; int n; int sure(long long median) { long long cnt1 = 0; long long cnt2 = 0; long long cnt3 = 0; long long sum = 0; vector<long long> tmp; f...
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; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { ll n, s; cin >> n >> s; vector<array<int, 2>> ranges(n); for (int i = 0; i < n; i++) { cin >> ranges[i][0] >> ranges[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 ...
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1000000007; int64_t l[200001]; int64_t r[200001]; int64_t get(int64_t x, int64_t s, int64_t n) { vector<int64_t> arr; int64_t a = 0, b = 0; for (int64_t i = 1; i <= n; i++) { if (r[i] < x) s -= l[i], a++; else if (l[i] >= x) 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 ...
// @uthor -: puneet // TimeStamp -: 11:27 PM - 31/10/19 import java.io.*; import java.math.BigInteger; import java.util.*; public class Bserach implements Runnable { public void solve() { int t=in.ni(); while (t-->0){ ArrayList<Pair> list=new ArrayList<>(); int n=in.ni(); ...
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 = 2e5 + 5; const long long inf = 1e14 + 5; inline long long min(long long a, long long b) { return a < b ? a : b; } struct Node { int l, r; } a[MAXN]; inline bool cmp_l(const Node &p, const Node &q) { return p.l < q.l; } int n; long long s; bool chk(int 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 ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; bool prime[1000001]; long long spf[10000001]; long long f[300005]; long long pow1(long long x, long long y) { long long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 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.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.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer...
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 isok(vector<pair<long long, long long> > &A, long long mid, long long s) { long long sum = 0, c = 0, left = 0, n = A.size(); vector<char> visited(n, 0); for (long long i = 0; i < (n); i++) { if (A[i].second < mid) { c++; sum += A[i].first; v...
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): l, r = info[i] if r < mid: ans += l elif mid < l: ans += l cnt += 1 else: tmp.append(l) tmp.sort(reverse = True) ...
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 = 2 * 1e5 + 1; struct Emp { int l, r; } emp[N]; bool search(int m, int n, long long s) { long long sum = 0, cnt = 0; for (int i = n - 1; i >= 0; i--) { if (emp[i].l >= m) cnt++; else if (emp[i].l <= m && emp[i].r >= m && cnt <= n / 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 ...
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; long long n, s, curs; const long long maxn = 2e5 + 10; pair<long long, long long> vec[maxn]; long long v[maxn]; bool check(long long mid) { if (mid == s + 1) return false; long long sz = 0; for (long long i = 0; i < n; i++) { if (vec[i].second >= mid) v[sz++] = ve...
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 ...
def main(): from array import array import sys input1 = sys.stdin.readline for _ in range(int(input1())): n, s = map(int, input1().split()) n1 = (n + 1) // 2 z = array('i', (0,)) ls = z * n rs = z * n for i in range(n): ls[i], rs[i] = map(int, ...
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 input = stdin.readline q = int(input()) for rwre in range(q): n, s = map(int,input().split()) przed = [list(map(int,input().split())) for i in range(n)] przed.sort() przed.reverse() l = 1 p = 10 ** 9 while abs(p - l) > 0: mozna = 1 sr = (p + l + 1) // 2 #try to make median >= sr duz...
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 ...
//Better and correct way to implement comparartor import java.io.*; import java.util.*; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); long sum=sc.nextLong(); Pair a[]=new Pair[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.util.*; import java.io.*; public class _1251d_salaryChanging { public static class node implements Comparable<node>{ int l,r; public node(int l,int r) { this.l=l; this.r=r; } @Override public int compareTo(node o) { if(this.l<o.l) return -1; else if(this.l==o.l && this.r<o.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 os import sys from io import BytesIO, IOBase from collections import Counter import math as mt 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 ...
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() { long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; vector<pair<int, int> > v; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()); 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 ...
#include <bits/stdc++.h> using namespace std; long long l[300100], r[300100]; long long n, sal; signed main() { long long t; scanf("%lld", &t); while (t--) { scanf("%lld %lld", &n, &sal); for (long long i = 1; i <= n; i++) scanf("%lld %lld", &l[i], &r[i]); long long bg = 1, nd = 1e9; while (bg < 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 n; struct node { long long l, r; } a1[200005], a2[200005], e[200005]; inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '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; struct node { int l, r; } a[200009]; int n; long long k; bool cmp(node aa, node bb) { if (aa.l == bb.l) return aa.r < bb.r; else return aa.l < bb.l; } int check(int x) { long long ans = 0; int w = 0; for (int i = n; i >= 1; i--) { if (w <= n / 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> const double PI = 3.141592653589793238460; using namespace std; pair<long long int, long long int> ar[200001]; bool isPossible(long long int mid, long long int s, long long int n) { long long int sum = 0; int cnt = 0; vector<int> va, vb, vc; for (int i = 1; i <= n; i++) { if (ar[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.PrintWriter; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.*; public class Main { static Comparator<long[]> comparator_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 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 ...
def main(): def getLowestPossibleMedian(lr,n): lr.sort(key=lambda x:x[0]) # sort by l asc return lr[n//2][0] def checkPossibleMedian(lr,guess,n,s): potentialUpper=[] # potential candidates for the upper half lower=[] lowerCnts=n//2 upperCnts=n-lowerCnts...
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 Main { static long func(long start,long end,int[][] l,long s) { if(start>end) { return Integer.MIN_VALUE; } long mid=(start+end)/2; long temp=s; int n=l.length; Arrays.sort(l,new Comparator<int[]>() { public int compare(int[] a,int[] b) { if(Math...
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 N = 2e5 + 7; const long long INF = 1e9; const long long MOD = INF + 7; long long n, s; vector<pair<long long, long long> > a; bool solve(long long m) { long long idx = (long long)n / 2; long long sm = 0; for (long long i = 0; i < n; i++) { sm += 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 ...
#include <bits/stdc++.h> using namespace std; int dirx[] = {1, -1, 0, 0}, diry[] = {0, 0, 1, -1}; long long bigmod(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = (res * x) % 998244353; x = (x * x) % 998244353; p >>= 1; } return res; } vector<pair<int, int> > inp; int 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 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 ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int t, n; long long s; struct uzi { int l, r; bool operator<(const uzi& t) const { return l > t.l; } } p[N]; int vis[N]; int main() { ios::sync_with_stdio(false); for (cin >> t; t; t--) { cin >> n >> s; long long S = 0; for (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 sys from collections import defaultdict def check(l,x,lim): low,high,n=[],[],len(l) for i in range(n): if l[i][1]<x: low.append(l[i][0]) else: high.append(l[i][0]) a,b=len(low),len(high) #high.sort() '''print(x,'x') print(low,'low') print(high,'...
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 itertools import bisect from collections import OrderedDict from sys import stdin, stdout class Solution: def __init__(self, n, s, salary_limits): self.n = n self.half_n = (n-1)//2 self.s = s self.salary_limits = salary_limits # Preprocessing self.l_sorted =...
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 Main { public static void main(String args[]) {new Main().run();} FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); void run(){ int q=in.nextInt(); for(int i=0;i<q;i++) { work(); } out.flush(); } long mod=1000000007; 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.*; import java.math.BigInteger; public class Main { static final int mod = (int)1e9+7; static int N = (int)2e6 + 2; static long[][] salary; public static void main(String[] args) throws Exception { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.o...
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; std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const double EPS = 1e-9; const double PI = acos(-1); const int MOD = 1000000007; vector<pair<long long, long long> > v; int n; long long s; bool test(long long x) { long long sum = 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 ...
def main(): import sys import heapq input = sys.stdin.readline t = int(input()) for _ in range(t): N, S = map(int, input().split()) cost = [] m = [] for _ in range(N): l, r = map(int, input().split()) cost.append((l, r)) m.append(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 ...
def main(): t=int(input()) allans=[] for _ in range(t): n,s=readIntArr() lr=[] for __ in range(n): lr.append(readIntArr()) lr.sort(key=lambda x:x[0]) guess=lr[n//2][0] # smallest possible median def isPossible(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 int N = 2e5 + 10; long long s, sum; int T, n; pair<int, int> L[N]; bool judge(long long val) { long long v = s; int num = (n + 1) / 2; for (int i = 1; i <= n; i++) { v -= L[i].first; if (L[i].first >= val) num--; } vector<int> cost; for (int 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 ...
#include <bits/stdc++.h> using namespace std; bool isValid(const long long& median, const vector<pair<long long, long long>>& ranges, const long long& s) { long long select_count = 0; long long sum = 0; for (int i = 0; i < ranges.size(); i++) { if (select_count < (ranges.size() + 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 sys input = sys.stdin.readline def judge(x): salary = [] left, right = 0, 0 l = [] for li, ri in lr: if ri<x: salary.append(li) left += 1 elif x<li: salary.append(li) right += 1 else: l.append((li, ri)) ...
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.BufferedInputStream; import java.io.InputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.Comparator; import java.util.Locale; import java.util.Scanner; public class DTask { private static final String QUICK_ANSWER = "NO"; private final Scanner in; private final ...
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 from collections import defaultdict as dd from collections import deque from fractions import Fraction as f def eprint(*args): print(*args, file=sys.stderr) zz=1 from math import * import copy #sys.setrecursionlimit(10**6) if zz: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.std...
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 def highest_median(ranges, s): n = len(ranges) ranges = sorted(ranges) low = ranges[n // 2][0] high = sorted(ranges, key=lambda x: x[1])[n // 2][1] + 1 while low + 1 < high: med = low + (high - low) // 2 smaller = 0 larger = 0 total = 0 for l, h 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; template <class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; } long long POW(long long a, long long p, long long M) { if (!p) return 1LL; long long T = POW(a, p / 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 double eps = 1e-10; const int INF = 0x3f3f3f3f, N = 1000005, M = 2000005, MOD = 2017; int sgn(double x) { return x < -eps ? -1 : (x < eps ? 0 : 1); } int Rand(int x) { return rand() * rand() % x + 1; } struct node { int l, r; bool operator<(const node &x) const { ...
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 MAXN = 2e5 + 5; pair<long long, long long> a[MAXN]; long long s; long long n; bool check(long long x) { long long sum = 0, cnt = 0; vector<long long> nums; for (long long i = 0; i < n; i++) { if (a[i].first >= x) { sum += a[i].first; cn...
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 pp = std::pair<int, int>; int main() { std::ios::sync_with_stdio(false); int t = 0; std::cin >> t; for (int k = 0; k < t; ++k) { int n = 0; long long s = 0, sum = 0; std::cin >> n >> s; pp p[n]; for (int i = 0; i < n; ++i) { std::cin >> p[i].first >> p[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; const long double PI = 2 * acos(0.0); void yes() { cout << "YES\n"; } void no() { cout << "NO\n"; cout << -1 << "\n"; exit(0); } long long m(long long a) { return (a + 1000000007) % 1000000007; } long long cel(long long x1, long long y1) { ; if ((x1 % y1) == 0) re...
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 = 2e5 + 10; long long t, n, m; struct p { long long l, r; bool operator<(const p& tmp) const { return l < tmp.l; } } a[maxn]; bool col(p a, p b) { return a.l < b.l; } bool cor(p a, p b) { return a.r > b.r; } bool isok(long long mid) { priority_queue<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 java.io.BufferedInputStream; import java.io.InputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.Comparator; import java.util.Locale; import java.util.Scanner; public class DTask { private static final String QUICK_ANSWER = "NO"; private final Scanner in; private final ...
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 = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 2e6 + 4; const int N = 5e3 + 5; const double eps = 1e-6; const double pi = acos(-1); long long qpow(long long x, long long y) { long long ans = 1; x %= mod; while (y) { if (y & 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 ...
from sys import stdin from operator import itemgetter, attrgetter def check(salary, mid, s): cnt = 0 for i in range(len(salary)): if salary[i][0] > mid: s -= salary[i][0] cnt += 1 elif salary[i][0] <= mid and salary[i][1] >= mid: if cnt < (len(salary) + 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 ...
#include <bits/stdc++.h> using namespace std; const long long int infinity = 9e18; pair<bool, long long int> isPossible( vector<pair<long long int, long long int> > &vp, long long int k, long long int s) { long long int n = vp.size(); vector<long long int> v, v1, v2; long long int a = 0, b = 0, c = 0; 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.*; import java.util.*; public class Main { public static void main(String args[]) { FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=input.nextInt(); while(T-->0) { int n=input.nextInt(); long s=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.*; public class Main { static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); static int oo = (int)1e9; static int mod = 1_000_000_007; static int[] di = {1, 0, 0, -1}; static int[] dj = {0, -1, 1, 0}; static int ...
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.Arrays; import java.util.Comparator; import java.util.Scanner; public class DDD { static pair[] dat; static int H=0; static long s=0; public static boolean possible(int median) { long sum=0; for(pair x:dat) { sum+=x.l; } int count=0; for(int i=dat.length-1;i>=0 && count<H;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.lang.*; import java.io.*; import java.util.*; public class Solution { static int n; static long s; static long arr[][]; static Integer ind[]; public static boolean calc(long x) { long avai=s; int c=0,i; for(i=n-1;i>=0;i--) { if(arr[ind[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; bool canDoAtLeast(long long m, long long s, vector<pair<long long, long long> > &E) { long long good = 0; vector<long long> P; for (auto [l, r] : E) { s -= l; if (l >= m) good++; else if (m <= r) { P.push_back(m - 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; using pii = pair<int, int>; using vi = vector<int>; using ll = long long; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; ll s; cin >> n >> s; vi l(n), r(n); for (int i = int(0); i < int(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 ...
import java.io.*; import java.util.*; public class Main { private static void execute(ContestReader reader, PrintWriter out) { int t = reader.nextInt(); for (int i = 0; i < t; i++) { int n = reader.nextInt(); long s = reader.nextLong(); int[] ls = new int[n]; int[] rs = new int[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; #pragma GCC optimization("Ofast") #pragma GCC optimization("unroll-loops") #pragma GCC target("avx2,avx,fma") int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int i, j, t; cin >> t; for (i = 0; i < t; i++) { int n; long l...