вроде должно работать
Объяснение:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
long long k, n;
cin >> n >> k;
vector<int> v;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
v.push_back(a);
}
int l = 1, r = 200, m;
while (l < r - 1) {
long long sum = 0;
m = (r + l) / 2;
sum += v[i] / m;
if (sum < k) {
r = m;
else {
l = m;
int sumL = 0, sumR = 0;
sumL += v[i] / l;
sumR += v[i] / r;
if (sumR == k) {
cout << r;
return 0;
else if (sumL==k){
cout << l;
cout << 0;
--- Python 3.8.3 ---
import random
def ShiftBorders(minValue, maxValue, token, assumption):
if token == '>':
minValue = assumption
elif token == '<':
maxValue = assumption
return (minValue, maxValue)
def main():
Reply = ''
lb, rb = 0, 100
while Reply != '=':
assumption = random.randint(lb, rb)
print(f'Is you choose {assumption}?')
Reply = input()
lb, rb = ShiftBorders(lb, rb, Reply, assumption)
else:
print('It was Easy')
if __name__ == "__main__":
main()
вроде должно работать
Объяснение:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
long long k, n;
cin >> n >> k;
vector<int> v;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
v.push_back(a);
}
int l = 1, r = 200, m;
while (l < r - 1) {
long long sum = 0;
m = (r + l) / 2;
for (int i = 0; i < n; i++) {
sum += v[i] / m;
}
if (sum < k) {
r = m;
}
else {
l = m;
}
}
int sumL = 0, sumR = 0;
for (int i = 0; i < n; i++) {
sumL += v[i] / l;
sumR += v[i] / r;
}
if (sumR == k) {
cout << r;
return 0;
}
else if (sumL==k){
cout << l;
return 0;
}
cout << 0;
return 0;
}
--- Python 3.8.3 ---
import random
def ShiftBorders(minValue, maxValue, token, assumption):
if token == '>':
minValue = assumption
elif token == '<':
maxValue = assumption
return (minValue, maxValue)
def main():
Reply = ''
lb, rb = 0, 100
while Reply != '=':
assumption = random.randint(lb, rb)
print(f'Is you choose {assumption}?')
Reply = input()
lb, rb = ShiftBorders(lb, rb, Reply, assumption)
else:
print('It was Easy')
if __name__ == "__main__":
main()