codesolvediscuss | Unsorted

Telegram-канал codesolvediscuss - Codeforces solutions | CodeSolve | discussion

1583

Subscribe to a channel

Codeforces solutions | CodeSolve | discussion

/channel/codesolvediscuss/22055

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Anyone can help me with C?

Читать полностью…

Codeforces solutions | CodeSolve | discussion

is there a easier way for problem c?

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Give the correct one

Читать полностью…

Codeforces solutions | CodeSolve | discussion

2 test cases passed but time limit exceeded on 3rd

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>

using namespace std;
#define int long long
int32_t main() {
int A;
cin >> A;
while (A--) {
int n, j, L;
cin >> n >> j >> L;
vector<pair<int, int>> vacency(L);
for (int i = 0; i < L; i++) {
cin >> vacency[i].first >> vacency[i].second;
}

auto calc_overlap = [&](int start) {
int cnt = 0;
for (auto job : vacency) {
if (max(job.first, start) <= min(job.second, start + j - 1)) {
cnt++;
}
}
return cnt;
};

int max_overlap = 0, min_overlap = L + 1;
int B = 1, M = 1;

for (int i = 1; i <= n - j + 1; i++) {
int op = calc_overlap(i);
if (op > max_overlap) {
max_overlap = op;
B = i;
}
if (op < min_overlap) {
min_overlap = op;
M = i;
}
}

cout<< B << " " << M << endl;
}
return 0;
}

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Can u send it in text?

Читать полностью…

Codeforces solutions | CodeSolve | discussion

It's AC ask people here

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Can Anyone please hint me with D

Читать полностью…

Codeforces solutions | CodeSolve | discussion

its will be tle n <= 2e5

Читать полностью…

Codeforces solutions | CodeSolve | discussion

I have c ac
whio has d ac ?

Читать полностью…

Codeforces solutions | CodeSolve | discussion

i share give me d solution

Читать полностью…

Codeforces solutions | CodeSolve | discussion

where's the problem?


#include <bits/stdc++.h> // подключаем библиотеку "bits/stdc++.h" со стандартной библиотекой шаблонов "(STL)"
#define int long long   // изменяем название типа данных "long long" на "int"
#define float double   // изменяем название типа данных "double" на "float"
using namespace std;  // подключаем пространство имён "std"


signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); //используем для ускорения ввода-вывода данных

    int t; cin >> t;
    while (t--)
    {
        int n; cin >> n;

        vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i];

        sort(v.begin(), v.end());

        int l = 0, r = 2000000, x = -1;

        while (l <= r)
        {
            int rich = l + (r - l) / 2;

            vector<int> b = v; b[n - 1] += rich;

            float sum = accumulate(b.begin(), b.end(), 0.0);
            float avg_wealth = sum / n;

            int counter = 0;
            for (int wealth : b)
            {
                if (wealth < avg_wealth / 2.0) counter++;
            }

            if (counter > n / 2)
            {
                x = rich;
                r = rich - 1;
            }
            else
            {
                l = rich + 1;
            }
        }

        cout << x << "\n";
    }
}

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>

using namespace std;
#define int long long
int32_t main() {
int t;
cin >> t;
while (t--) {
int n, d, k;
cin >> n >> d >> k;
vector<pair<int, int>> jobs(k);
for (int i = 0; i < k; i++) {
cin >> jobs[i].first >> jobs[i].second;
}

auto calc_overlap = [&](int start) {
int count = 0;
for (auto job : jobs) {
if (max(job.first, start) <= min(job.second, start + d - 1)) {
count++;
}
}
return count;
};

int max_overlap = 0, min_overlap = k + 1;
int best_brother = 1, best_mother = 1;

for (int i = 1; i <= n - d + 1; i++) {
int overlap = calc_overlap(i);
if (overlap > max_overlap) {
max_overlap = overlap;
best_brother = i;
}
if (overlap < min_overlap) {
min_overlap = overlap;
best_mother = i;
}
}

cout << best_brother << " " << best_mother << endl;
}
return 0;
}

Читать полностью…

Codeforces solutions | CodeSolve | discussion

SHARE GROUP FOR D SOLUTION

Читать полностью…

Codeforces solutions | CodeSolve | discussion

You got me bro😍
Thanks

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Yes . But i dont no . Correct or not . Try

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>
using namespace std;
#define int long long


int32_t main(){
int t;
cin>>t;
while(t--){
int n,d,k;
cin>>n>>d>>k;
//vector<int>v(n+2,0);
int l,r;
map<int,int>start,end;
while(k--){
cin>>l>>r;
start[l]++;
end[r]++;
}
int mom=0,conv=0,bro=0,momind=1,broind=1;

for(int i=1; i<=d; i++){
if(start.find(i)!=start.end()){
conv+=start[i];
}
}
mom=bro=conv;
//cout<<conv<<" ";
for(int i=2; i<=n-d+1; i++){
if(start.find(i+d-1)!=start.end()){

conv+=start[i+d-1];
}
if(end.find(i-1)!=end.end()){
conv-=end[i-1];
}
//cout<<conv<< " ";
if(conv>bro){
bro=conv;
broind=i;
}
if(mom>conv){
mom=conv;
momind=i;
}
}
//cout<<endl;
cout<<broind<<" "<<momind<<endl;
}
}

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Yup and some r saying that it got accepted

Читать полностью…

Codeforces solutions | CodeSolve | discussion

all answer for D were wrong , please send the correct one

Читать полностью…

Codeforces solutions | CodeSolve | discussion

No, we don't need skip

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Someone Send it with text

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Is it correct for D?

Читать полностью…

Codeforces solutions | CodeSolve | discussion

send code if it's AC, that will sure TLE

Читать полностью…

Codeforces solutions | CodeSolve | discussion

it works in VScode but when I send wrong answer so what?

Читать полностью…

Codeforces solutions | CodeSolve | discussion

I have C . Give me D

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Adolf скажи ему пару ласковых

Читать полностью…

Codeforces solutions | CodeSolve | discussion

dies on the 4th test

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Can anyone only hint me D, just hint

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include<bits/stdc++.h>
using namespace std;

const int INF = 1e18;

// Function to check if adding "additionValue" will make more than half of the elements below the new average
bool isValidMidpoint(int n, vector<int>& array, int totalSum, int additionValue) {
vector<int> newArray = array; // Copy of the original array
newArray[n-1] += additionValue; // Add the value to the last element
int newSum = totalSum + additionValue;
double newAverage = newSum / (2.0 * n); // New average based on the new total sum
int countBelowAverage = 0;

for (int i = 0; i < n; i++) {
if (newAverage > newArray[i]) {
countBelowAverage++;
}
}
return countBelowAverage > n / 2;
}

// Function to perform binary search to find the minimum addition value
int findMinimumAdditionValue(int n, vector<int>& array, int totalSum) {
int left = 0, right = INF, bestAddition = -1;

while (left <= right) {
int midpoint = left + (right - left) / 2;

if (isValidMidpoint(n, array, totalSum, midpoint)) {
bestAddition = midpoint;
right = midpoint - 1; // Try for a smaller value
} else {
left = midpoint + 1; // Try for a larger value
}
}

return bestAddition;
}

// Function to process each test case
void processTestCase() {
int n;
cin >> n;
int totalSum = 0;
vector<int> array(n);

for (int i = 0; i < n; i++) {
cin >> array[i];
totalSum += array[i];
}

// If the array is too small, output -1
if (n == 1) {
cout << -1 << endl;
return;
}
if(n == 2)
{
cout << -1 << endl;
return;
}
// Sort the array for easier comparison
sort(array.begin(), array.end());

// Calculate the initial average
int countBelowAverage = 0;



// Find the minimum addition value using binary search
int result = findMinimumAdditionValue(n, array, totalSum);
cout << result << endl;
}

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

int testCases;
cin >> testCases;

while (testCases--) {
processTestCase();
}

return 0;
}


C solution and write long long instead of int everywhere

Читать полностью…
Subscribe to a channel