# A. Mind the Gap

```#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;

int main()
{
int n,s;
cin >> n >> s;
int h,m;
int nh,nm,neh,nem;
nh = 0;
nm = 0;
nem = (nm + s + 1) % 60;
neh = nh + (nm + s + 1) / 60;
bool ok = false;
for(int i=0;i<n;i++)
{
cin >> h >> m;
if(h>neh||(h==neh&&m>=nem))
{
cout << nh << " " << nm << endl;
ok = true;
break;
}
else
{
nm = (m + s + 1) % 60;
nh = h + (m + s + 1) / 60;
nem = (nm + s + 1) % 60;
neh = nh + (nm + s + 1) / 60;
}
}
if(!ok)
{
cout << nh << " " << nm << endl;
}
return 0;
}
```

# B. Watering System

```#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;
const double eps = 1e-6;

int s[maxn];

int main()
{
int n,A,B;
ios::sync_with_stdio(false);
cin >> n >> A >> B;
double sum = 0.0;
for(int i=0;i<n;i++)
{
cin >> s[i];
sum += s[i];
}
double need = (double)(s[0] * A) / (double)(B);
sort(s+1,s+n);
int pos = n;
//cout << need << " " << sum-eps << endl;
if(need < sum - eps)
{
for(pos=n-1;pos>0;pos--)
{
sum -= s[pos];
//cout << pos << "*" << sum << "*" << need-eps << endl;
if(sum <= need + eps)
{
break;
}
}
}
cout << n - pos << endl;
//cout << need << endl;
return 0;
}
```

# C. Stairs and Elevators

```#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;

int ll[maxn];
int ee[maxn];

int myabs(int k)
{
if(k <0)
{
k *= (-1);
}
return k;
}

int main()
{
ios::sync_with_stdio(false);
//freopen("in.txt","r",stdin);
int n,m,cl,ce,v;
cin >> n >> m >> cl >> ce >> v;
for(int i=0;i<cl;i++)
{
cin >> ll[i];
}
for(int i=0;i<ce;i++)
{
cin >> ee[i];
}
int q;
cin >> q;
while(q--)
{
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
if(y1 > y2)
{
int temp = y1;
y1 = y2;
y2 = temp;
temp = x1;
x1 = x2;
x2 = temp;
}
if(x1 == x2)
{
cout << y2 - y1 << endl;
continue;
}
int sum = 2e9 + 10;
int pos = lower_bound(ee,ee+ce,y1)-ee;
int pos2 = pos-1;
int hh = (myabs(x1-x2) - 1) / v + 1;
if(pos < ce)
{
if(ee[pos] < y2)
{
sum = y2 - y1 + hh;
//con = false;
//cout << "1*" << sum << endl;
}
else
{
int tempsum = ee[pos] - y2 + ee[pos] - y1 + hh;
//cout << "2*" << tempsum << endl;
if(tempsum < sum)
{
sum = tempsum;
}
}
}
if(pos2 >= 0)
{
int tempsum = y2 - ee[pos2] + y1 - ee[pos2] + hh;
//cout << "3*" << tempsum << endl;
if(tempsum < sum)
{
sum = tempsum;
}
}
pos = lower_bound(ll,ll+cl,y1)-ll;
pos2 = pos-1;
hh = myabs(x1-x2);
if(pos < cl)
{
if(ll[pos] < y2)
{
int tempsum = y2 - y1 + hh;
//cout << "4*" << tempsum << endl;
if(tempsum < sum)
{
sum = tempsum;
}
//con = false;
}
else
{
int tempsum = ll[pos] - y2 + ll[pos] - y1 + hh;
//cout << "5*" << tempsum << endl;
if(tempsum < sum)
{
sum = tempsum;
}
}
}
if(pos2 >= 0)
{
int tempsum = y2 - ll[pos2] + y1 - ll[pos2] + hh;
//cout << "6*" << tempsum << endl;
if(tempsum < sum)
{
sum = tempsum;
}
}
cout << sum << endl;
}
return 0;
}
```

# D. Resource Distribution

```#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 3e5+10;

const double eps = 1e-6;

map<int,vector<int> > pos;
map<int,int> num;

vector<int> rere1,rere2;

bool ccin[maxn];
int cc[maxn];
int cc0[maxn];

int main()
{
int n,x1,x2;
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);
while(cin >> n >> x1 >> x2)
{
int re1,re2;
bool rev = false;
pos.clear();
num.clear();
rere1.clear();
rere2.clear();
memset(ccin,true,sizeof(ccin));
//double dif = 0;
for(int i=0;i<n;i++)
{
int temp;
cin >> temp;
pos[temp].push_back(i+1);
num[temp]++;
//dif += (double)(temp);
cc[i] = temp;
cc0[i] = temp;
}
sort(cc,cc+n);
/*if(x1<x2)
{
rev = true;
int temp = x2;
x2 = x1;
x1 = temp;
}*/
bool ok = false;
while(!ok)
{
if(rev)
{
pos.clear();
num.clear();
rere1.clear();
rere2.clear();
memset(ccin,true,sizeof(ccin));
pos.clear();
num.clear();
for(int i=0;i<n;i++)
{
int temp = cc0[i];
pos[temp].push_back(i+1);
num[temp]++;
}
sort(cc,cc+n);
}
int did;
int nownum = n-1;
int ti = 0;
//int dif = cc[n-1]+1;
int tempnownum;
//double tempsum = 0;
//int fi = n-1;
for(did=1;did<=n;did++)
{
double temp = (double)(x1) / (double)(did);
while(nownum>=0&&(/*(!ccin[nownum])||*/(temp-eps <= (double)(cc[nownum]))))
{
//cout << "&";
//if(ccin[nownum])
//{
ti++;
//tempsum += (double)(cc[nownum]);
//}
nownum--;
}
//cout << ti << "^^" << did << "^^"<< tempsum<< endl;
//cout << ti << "*" << did << "*" << nownum <<endl;
if(ti>=did)
{
while(ti>did)
{
//tempsum -= (double)(cc[fi]);
//fi--;
ti--;
}
//double tempdif = 0;
ok = true;
/*for(int i=0,j=nownum+1;i<did;i++,j++)
{
tempdif += cc[j] - (int)(temp);
//      cout << "#" << nowpos << "#" << num[nowpos] << "#" << pos[nowpos][num[nowpos]-1] << endl;
}*/
//tempdif = tempsum - ceil(temp) * (double)(did);
//cout << tempdif <<  "&&" <<nownum << "&&" << did<< endl;
//if(tempdif < dif + eps)
//{
//dif = tempdif;
/*if(ok)
{
for(int i=0,j=tempnownum+1;i<re1;i++,j++)
{
int nowpos = cc[j];
rere1.clear();
//      cout << "#" << nowpos << "#" << num[nowpos] << "#" << pos[nowpos][num[nowpos]-1] << endl;
num[nowpos] ++;
ccin[j] = true;
}
}
else
{
ok = true;
}
for(int i=0,j=nownum+1;i<did;i++,j++)
{
int nowpos = cc[j];
rere1.push_back(pos[nowpos][num[nowpos]-1]);
//      cout << "#" << nowpos << "#" << num[nowpos] << "#" << pos[nowpos][num[nowpos]-1] << endl;
num[nowpos] --;
ccin[j] = false;
}*/
tempnownum = nownum;
re1 = did;
//}
/*if(n==4&&x1==12&&x2==11)
{
}
else
{*/
break;
//}
}
}
if(ok)
{
for(int i=0,j=tempnownum+1;i<re1;i++,j++)
{
int nowpos = cc[j];
rere1.push_back(pos[nowpos][num[nowpos]-1]);
//      cout << "#" << nowpos << "#" << num[nowpos] << "#" << pos[nowpos][num[nowpos]-1] << endl;
num[nowpos] --;
ccin[j] = false;
}
ok = false;
nownum = n-1;
int ti = 0;
for(did=1;did<=n;did++)
{
double temp = (double)(x2) / (double)(did);
while(nownum>=0&&((!ccin[nownum])||(temp-eps <= cc[nownum])))
{
//    cout << "&";
if(ccin[nownum])
{
ti++;
}
nownum--;
}
//cout << ti << "*" << did << "*" << nownum <<endl;
if(ti>=did)
{
ok = true;
re2 = did;
for(int i=0,j=nownum+1;i<did;i++,j++)
{
while(!ccin[j])
{
j++;
}
int nowpos = cc[j];
rere2.push_back(pos[nowpos][num[nowpos]-1]);
//      cout << "#" << nowpos << "#" << num[nowpos] << "#" << pos[nowpos][num[nowpos]-1] << endl;
num[nowpos] --;
ccin[j] = false;
}
break;
}
}
}
if(ok||rev)
{
break;
}
else
{
rev = true;
int temp = x2;
x2 = x1;
x1 = temp;
}
}
if(ok)
{
if(rev)
{
cout << "Yes\n" << re2 << " " << re1 << "\n" << rere2[0];
for(int i=1;i<re2;i++)
{
cout << " " << rere2[i];
}
cout << "\n" << rere1[0];
for(int i=1;i<re1;i++)
{
cout << " " << rere1[i];
}
cout << endl;
}
else
{
cout << "Yes\n" << re1 << " " << re2 << "\n" << rere1[0];
for(int i=1;i<re1;i++)
{
cout << " " << rere1[i];
}
cout << "\n" << rere2[0];
for(int i=1;i<re2;i++)
{
cout << " " << rere2[i];
}
cout << "\n";
}
}
else
{
cout << "No\n";
}
}
return 0;
}

/*最小差值a

```