#include<bits/stdc++.h>#define int long longusingnamespace std;struct node
{int mon;int fri;};boolcmp(node x, node y){return x.mon < y.mon;}constint maxn =1e5+5;
node a[maxn];int b[maxn];int sum[maxn];signedmain(){int n, d;
cin >> n >> d;for(int i =0; i < n; i ++){
cin >> a[i].mon >> a[i].fri;}sort(a, a + n, cmp);for(int i =1; i <= n; i ++){
b[i -1]= a[i -1].mon;
sum[i]= sum[i -1]+ a[i -1].fri;}int ans =0;for(int i =0; i < n; i ++){int it =upper_bound(b, b + n, a[i].mon + d -1)- b;
ans =max(ans, sum[it]- sum[i]);}
cout << ans;return0;}
#include<bits/stdc++.h>#define int long longusingnamespace std;constint maxn =100000+5;int a[maxn], b[maxn];signedmain(){int n, k;
cin >> n >> k;for(int i =1; i <= n; i ++){
cin >> a[i];}for(int i = n - k, j = n - k +1; i >=1; i --, j ++){
a[i]+= a[j];}sort(a +1, a +1+ n);
cout << a[n];return0;}
#include<iostream>#define int long longusingnamespace std;constint maxn =100000+5;int a[maxn];signedmain(){int n;while(cin >> n){int most =0;for(int i =0; i < n; i ++){scanf("%lld",&a[i]);
most =max(most, a[i]);}int k;
cin >> k;if(k ==1){
cout << most << endl;continue;}int l =0, r = most;while(l != r){int mid =(r + l)/2;int t =0;for(int i =0; i < n; i ++){if(a[i]> mid){
t +=(a[i]- mid)/(k -1);if((a[i]- mid)%(k -1)){
t ++;}}}if(t <= mid){
r = mid;}else{
l = mid +1;}}
cout << l << endl;}return0;}
#include<iostream>#include<algorithm>#define int long longusingnamespace std;constint maxn =500000+5;int a[maxn];int l, n, m;boolcheck(int ans){int vis =0;for(int i =1; i <= m; i ++){
vis =upper_bound(a, a + n, a[vis]+ ans)- a -1;if(vis >= n -1)return1;}return0;}signedmain(){int lef, rig, mid;while(cin >> l >> n >> m){
a[0]=0;for(int i =1; i <= n; i ++){scanf("%lld",&a[i]);}
a[n +1]= l;
n +=2;sort(a, a + n);
lef = l / m, rig = l;while(lef <= rig){int mid = lef + rig >>1;if(check(mid)) rig = mid -1;else lef = mid +1;}printf("%lld\n", lef);}return0;}
#include<iostream>#define int long longusingnamespace std;constint inf =0x3f3f3f;constint maxn =100000+5;int a[maxn];signedmain(){int t;
cin >> t;while(t --){int n, s;scanf("%lld%lld",&n,&s);for(int i =0; i < n; i ++){scanf("%lld",&a[i]);}int ans = inf, sum =0;for(int i =0, j =0; i < n; i ++){while(sum < s && j < n){
sum += a[j ++];}if(sum >= s){
ans =min(ans, j - i);}
sum -= a[i];}if(ans == inf) ans =0;printf("%lld\n", ans);}return0;}
A - Kefa and Company #include<bits/stdc++.h>#define int long longusing namespace std;struct node { int mon; int fri;};bool cmp(node x, node y) { return x.mon < y.mon;}const int maxn = 1e5 + 5;node a[maxn];int b[maxn];int sum[max