1670D - Very Suspicious - CodeForces Solution


binary search brute force geometry greedy implementation math *1700

Please click on ads to support us..

Python Code:

import sys, math
input = sys.stdin.readline
for _ in range(int(input())): print(math.ceil(math.sqrt(3/2*int(input()))))

C++ Code:

// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>

#define endl "\n"
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;

const int N = 1000010;

int a[N];
ll T,n,m;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};


int main()
{
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	vector<int> ans;
	int mx = 0;
	int x = 0;
	priority_queue<int,vector<int>,greater<int>> heap;
	for(int i=0;i<3;i++) heap.push(0);
	
	while(x < 1e9+7){
		ans.push_back(x);
		int mn = heap.top();
		heap.pop();
		x += 2*(mx - mn);
		mx++;
		mn++;
		heap.push(mn);
	}
	cin >> T;
	while(T--){
		cin >> n;
		cout << lower_bound(ans.begin(),ans.end(),n) - ans.begin() << endl;
	}
	
    return 0;
}


Comments

Submit
0 Comments
More Questions

Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses