#include <bits/stdc++.h>
#define X first
#define Y second
#define MP make_pair
#define ll long long
using namespace std;
const int N = 1e5 + 123;
struct node{
node *left, *right;
ll key, pr, size, tt;
node(ll val){
key = val;
pr = rand() << 15;
cout << pr << "\n";
size = 1;
tt = 0;
left = right = nullptr;
}
};
int get_sz(node* v){
return v == nullptr ? 0 : v->size;
}
node* update(node* root){
if(root == nullptr)
return nullptr;
root->size = get_sz(root->left) + get_sz(root->right) + 1;
if(root->left != nullptr){
root->left->key += root->tt;
root->left->tt += root->tt;
}
if(root->right != nullptr){
root->right->key += root->tt;
root->right->tt += root->tt;
}
root->tt = 0;
return root;
}
pair<node*, node*> split(node* root, ll key){
if(root == nullptr){
return MP(nullptr, nullptr);
}
root = update(root);
if(root->key >= key){
pair<node*, node*> splitted = split(root->left, key);
splitted.X = update(splitted.X);
splitted.Y = update(splitted.Y);
root->left = splitted.Y;
root = update(root);
return MP(splitted.X, root);
}
else{
pair<node*, node*> splitted = split(root->right, key);
splitted.X = update(splitted.X);
splitted.Y = update(splitted.Y);
root->right = splitted.X;
root = update(root);
return MP(root, splitted.Y);
}
}
node* insert(node* root, node* vertex){
if(root == nullptr){
return vertex;
}
root = update(root);
cout << root->key << " -- " << vertex->key << "\n";
if(root->pr > vertex->pr){
if(root->key > vertex->key){
root->left = insert(root->left, vertex);
update(root->left);
}
else{
root->right = insert(root->right, vertex);
update(root->right);
}
}
else{
pair<node*, node*> splitted = split(root, vertex->key);
splitted.X = update(splitted.X);
splitted.Y = update(splitted.Y);
vertex->left = splitted.X;
vertex->right = splitted.Y;
root = vertex;
}
root = update(root);
return root;
}
int n, k;
ll a[N];
ll solve(ll val){
node* root = nullptr;
ll cnt = 0;
for(int i = 1;i <= n;i++){
if(i == 1){
root = new node(a[1]);
}
else{
root->tt += a[i], root->key += a[i];
root = update(root);
root = insert(root, new node(a[i]));
}
cout << val << " " << root->size << "\n";
pair<node*, node*> splitted = split(root, val);
if(splitted.Y != nullptr){
cnt += splitted.Y->size;
}
cout << val << " " << root->size << "\n";
}
return cnt;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(chrono::system_clock::now().time_since_epoch().count());
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
ll tl = -1e14 - 1, tr = 1e14 + 1;
ll tp = 1e14;
while(tl <= tr){
ll tm = (tl + tr) / 2;
ll cnt = solve(tm);
// cout << cnt << " " << tm << "\n";
if(cnt < k){
tr = tm - 1;
}
else{
tl = tm + 1;
tp = tm;
}
}
cout << tp;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAKI2RlZmluZSBYIGZpcnN0CiNkZWZpbmUgWSBzZWNvbmQKI2RlZmluZSBNUCBtYWtlX3BhaXIKI2RlZmluZSBsbCBsb25nIGxvbmcgCiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApjb25zdCBpbnQgTiA9IDFlNSArIDEyMzsKCnN0cnVjdCBub2RlewoJbm9kZSAqbGVmdCwgKnJpZ2h0OwoJbGwga2V5LCBwciwgc2l6ZSwgdHQ7Cglub2RlKGxsIHZhbCl7CgkJa2V5ID0gdmFsOwoJCXByID0gcmFuZCgpIDw8IDE1OwoJCWNvdXQgPDwgcHIgPDwgIlxuIjsKCQlzaXplID0gMTsKCQl0dCA9IDA7CgkJbGVmdCA9IHJpZ2h0ID0gbnVsbHB0cjsKCX0KfTsKCmludCBnZXRfc3oobm9kZSogdil7CglyZXR1cm4gdiA9PSBudWxscHRyID8gMCA6IHYtPnNpemU7Cn0KCm5vZGUqIHVwZGF0ZShub2RlKiByb290KXsKCWlmKHJvb3QgPT0gbnVsbHB0cikKCQlyZXR1cm4gbnVsbHB0cjsKCXJvb3QtPnNpemUgPSBnZXRfc3oocm9vdC0+bGVmdCkgKyBnZXRfc3oocm9vdC0+cmlnaHQpICsgMTsKCWlmKHJvb3QtPmxlZnQgIT0gbnVsbHB0cil7CgkJcm9vdC0+bGVmdC0+a2V5ICs9IHJvb3QtPnR0O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BkYXRlKHJvb3QpOwoJCQlyb290ID0gaW5zZXJ0KHJvb3QsIG5ldyBub2RlKGFbaV0pKTsKCQl9CgkJY291dCA8PCB2YWwgPDwgIiAiIDw8IHJvb3QtPnNpemUgPDwgIlxuIjsKCQlwYWlyPG5vZGUqLCBub2RlKj4gc3BsaXR0ZWQgPSBzcGxpdChyb290LCB2YWwpOwoJCWlmKHNwbGl0dGVkLlkgIT0gbnVsbHB0cil7CgkJCWNudCArPSBzcGxpdHRlZC5ZLT5zaXplOwoJCX0KCQljb3V0IDw8IHZhbCA8PCAiICIgPDwgcm9vdC0+c2l6ZSA8PCAiXG4iOwoJfQoJcmV0dXJuIGNudDsKfQoKaW50IG1haW4gKCkgewoJaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CgljaW4udGllKDApOwoJY291dC50aWUoMCk7CglzcmFuZChjaHJvbm86OnN5c3RlbV9jbG9jazo6bm93KCkudGltZV9zaW5jZV9lcG9jaCgpLmNvdW50KCkpOwogICAJCiAgIAljaW4gPj4gbiA+PiBrOwogICAJZm9yKGludCBpID0gMTtpIDw9IG47aSsrKXsKICAgCQljaW4gPj4gYVtpXTsKICAgCX0KICAgCWxsIHRsID0gLTFlMTQgLSAxLCB0ciA9IDFlMTQgKyAxOwogICAJbGwgdHAgPSAxZTE0OwogICAJd2hpbGUodGwgPD0gdHIpewogICAJCWxsIHRtID0gKHRsICsgdHIpIC8gMjsKICAgCQlsbCBjbnQgPSBzb2x2ZSh0bSk7CiAgIAkvLwljb3V0IDw8IGNudCA8PCAiICIgPDwgdG0gPDwgIlxuIjsKICAgCQlpZihjbnQgPCBrKXsKICAgCQkJdHIgPSB0bSAtIDE7CiAgIAkJfQogICAJCWVsc2V7CiAgIAkJCXRsID0gdG0gKyAxOwogICAJCQl0cCA9IHRtOwogICAJCX0KICAgCX0KICAgCWNvdXQgPDwgdHA7CiAgIAlyZXR1cm4gMDsKfQ==
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
^
Main.java:3: error: illegal character: '#'
#define X first
^
Main.java:4: error: illegal character: '#'
#define Y second
^
Main.java:5: error: illegal character: '#'
#define MP make_pair
^
Main.java:6: error: illegal character: '#'
#define ll long long
^
Main.java:10: error: class, interface, or enum expected
const int N = 1e5 + 123;
^
Main.java:12: error: class, interface, or enum expected
struct node{
^
Main.java:14: error: class, interface, or enum expected
ll key, pr, size, tt;
^
Main.java:15: error: class, interface, or enum expected
node(ll val){
^
Main.java:17: error: class, interface, or enum expected
pr = rand() << 15;
^
Main.java:18: error: class, interface, or enum expected
cout << pr << "\n";
^
Main.java:19: error: class, interface, or enum expected
size = 1;
^
Main.java:20: error: class, interface, or enum expected
tt = 0;
^
Main.java:21: error: class, interface, or enum expected
left = right = nullptr;
^
Main.java:22: error: class, interface, or enum expected
}
^
Main.java:25: error: class, interface, or enum expected
int get_sz(node* v){
^
Main.java:27: error: class, interface, or enum expected
}
^
Main.java:32: error: class, interface, or enum expected
root->size = get_sz(root->left) + get_sz(root->right) + 1;
^
Main.java:33: error: class, interface, or enum expected
if(root->left != nullptr){
^
Main.java:35: error: class, interface, or enum expected
root->left->tt += root->tt;
^
Main.java:36: error: class, interface, or enum expected
}
^
Main.java:39: error: class, interface, or enum expected
root->right->tt += root->tt;
^
Main.java:40: error: class, interface, or enum expected
}
^
Main.java:42: error: class, interface, or enum expected
return root;
^
Main.java:43: error: class, interface, or enum expected
}
^
Main.java:48: error: class, interface, or enum expected
}
^
Main.java:50: error: class, interface, or enum expected
if(root->key >= key){
^
Main.java:52: error: class, interface, or enum expected
splitted.X = update(splitted.X);
^
Main.java:53: error: class, interface, or enum expected
splitted.Y = update(splitted.Y);
^
Main.java:54: error: class, interface, or enum expected
root->left = splitted.Y;
^
Main.java:55: error: class, interface, or enum expected
root = update(root);
^
Main.java:56: error: class, interface, or enum expected
return MP(splitted.X, root);
^
Main.java:57: error: class, interface, or enum expected
}
^
Main.java:60: error: class, interface, or enum expected
splitted.X = update(splitted.X);
^
Main.java:61: error: class, interface, or enum expected
splitted.Y = update(splitted.Y);
^
Main.java:62: error: class, interface, or enum expected
root->right = splitted.X;
^
Main.java:63: error: class, interface, or enum expected
root = update(root);
^
Main.java:64: error: class, interface, or enum expected
return MP(root, splitted.Y);
^
Main.java:65: error: class, interface, or enum expected
}
^
Main.java:71: error: class, interface, or enum expected
}
^
Main.java:73: error: class, interface, or enum expected
cout << root->key << " -- " << vertex->key << "\n";
^
Main.java:74: error: class, interface, or enum expected
if(root->pr > vertex->pr){
^
Main.java:77: error: class, interface, or enum expected
update(root->left);
^
Main.java:78: error: class, interface, or enum expected
}
^
Main.java:81: error: class, interface, or enum expected
update(root->right);
^
Main.java:82: error: class, interface, or enum expected
}
^
Main.java:86: error: class, interface, or enum expected
splitted.X = update(splitted.X);
^
Main.java:87: error: class, interface, or enum expected
splitted.Y = update(splitted.Y);
^
Main.java:88: error: class, interface, or enum expected
vertex->left = splitted.X;
^
Main.java:89: error: class, interface, or enum expected
vertex->right = splitted.Y;
^
Main.java:90: error: class, interface, or enum expected
root = vertex;
^
Main.java:91: error: class, interface, or enum expected
}
^
Main.java:93: error: class, interface, or enum expected
return root;
^
Main.java:94: error: class, interface, or enum expected
}
^
Main.java:97: error: class, interface, or enum expected
ll a[N];
^
Main.java:99: error: class, interface, or enum expected
ll solve(ll val){
^
Main.java:101: error: class, interface, or enum expected
ll cnt = 0;
^
Main.java:102: error: class, interface, or enum expected
for(int i = 1;i <= n;i++){
^
Main.java:102: error: class, interface, or enum expected
for(int i = 1;i <= n;i++){
^
Main.java:102: error: class, interface, or enum expected
for(int i = 1;i <= n;i++){
^
Main.java:105: error: class, interface, or enum expected
}
^
Main.java:108: error: class, interface, or enum expected
root = update(root);
^
Main.java:109: error: class, interface, or enum expected
root = insert(root, new node(a[i]));
^
Main.java:110: error: class, interface, or enum expected
}
^
Main.java:112: error: class, interface, or enum expected
pair<node*, node*> splitted = split(root, val);
^
Main.java:113: error: class, interface, or enum expected
if(splitted.Y != nullptr){
^
Main.java:115: error: class, interface, or enum expected
}
^
Main.java:117: error: class, interface, or enum expected
}
^
Main.java:119: error: class, interface, or enum expected
}
^
Main.java:123: error: class, interface, or enum expected
cin.tie(0);
^
Main.java:124: error: class, interface, or enum expected
cout.tie(0);
^
Main.java:125: error: class, interface, or enum expected
srand(chrono::system_clock::now().time_since_epoch().count());
^
Main.java:127: error: class, interface, or enum expected
cin >> n >> k;
^
Main.java:128: error: class, interface, or enum expected
for(int i = 1;i <= n;i++){
^
Main.java:128: error: class, interface, or enum expected
for(int i = 1;i <= n;i++){
^
Main.java:128: error: class, interface, or enum expected
for(int i = 1;i <= n;i++){
^
Main.java:130: error: class, interface, or enum expected
}
^
Main.java:132: error: class, interface, or enum expected
ll tp = 1e14;
^
Main.java:133: error: class, interface, or enum expected
while(tl <= tr){
^
Main.java:135: error: class, interface, or enum expected
ll cnt = solve(tm);
^
Main.java:137: error: class, interface, or enum expected
if(cnt < k){
^
Main.java:139: error: class, interface, or enum expected
}
^
Main.java:142: error: class, interface, or enum expected
tp = tm;
^
Main.java:143: error: class, interface, or enum expected
}
^
Main.java:146: error: class, interface, or enum expected
return 0;
^
Main.java:147: error: class, interface, or enum expected
}
^
87 errors