#include <bits/stdc++.h>usingnamespacestd;
int main()
{
longlong ts, tf, t, n, p, i, j, ans, b, a, min = 1e12+7;
cin >> ts >> tf >> t;
cin >> n;
ans = ts;
b = ts;
for (i = 0; i < n; i++)
{
cin >> a;
if (b + t > tf)
break;
if (a <= b)
{
if (b - a + 1 < min)
{
min = b - a + 1;
ans = a - 1;
}
b += t;
}
else
{
cout << b;
return0;
}
}
if (b + t <= tf)
cout << b;
elsecout << ans;
return0;
}
#include <bits/stdc++.h>usingnamespacestd;
vector<int> v[1000001], ans;
int val[1000001], dp[1000001];
longlong tot;
void dfs(int x, int y)
{
dp[x] = val[x];
int i, j, z;
for (i = 0; i < v[x].size(); i++)
{
z = v[x][i];
if (z != y)
{
dfs(z, x);
if (dp[z] == tot)
ans.push_back(z);
else
dp[x] += dp[z];
}
}
}
int main()
{
int n, i, p, c;
tot = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%d%d", &p, &c);
v[p].push_back(i);
v[i].push_back(p);
val[i] = c;
tot += c;
}
if (tot % 3)
{
printf("-1");
exit(0);
}
tot /= 3;
dfs(v[0][0], 0);
if (ans.size() < 2)
printf("-1");
elseprintf("%d %d", ans[0], ans[1]);
return0;
}
#include <bits/stdc++.h>usingnamespacestd;
pair<int, int> sm[1000010];
int n, m, k, tou[10000010] = {0}, sc[1000010];
int main()
{
int a, i, j, t = 0, p = 0;
cin >> n >> m >> k;
for (i = 1; i <= n; i++)
{
scanf("%d", &a);
tou[a]++;
}
for (i = 0; i <= 10000000; i++)
{
tou[i] = k - tou[i];
if (tou[i] < 0)
{
cout << "-1";
return0;
}
}
for (i = 1; i <= m; i++)
{
scanf("%d", &sm[i].first);
sm[i].second = i;
}
sort(sm + 1, sm + m + 1);
for (i = 1; i <= m; i++)
{
for (j = p; j <= sm[i].first; j++)
if (tou[j] > 0)
{
tou[j]--;
if (tou[j] == 0)
while (tou[p] == 0)
p++;
t++;
sc[t] = sm[i].second;
break;
}
}
printf("%d\n", t);
for (i = 1; i <= t; i++)
printf("%d ", sc[i]);
}
#include <bits/stdc++.h>usingnamespacestd;
constint N = 233333, M = 111;
longlong w[N];
int f[N], c[N];
struct node
{
int i;
boolfriendoperator<(node a, node b)
{
return w[a.i] > w[b.i];
}
};
priority_queue<node> q;
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
{
scanf("%d", &c[i]);
}
for (int i = 0; i < n; i++)
{
int k;
scanf("%d", &k);
w[i] = k * (100 - c[i] % 100);
}
longlong ans = 0;
memset(f, 0, sizeof(f));
for (int i = 0; i < n; i++)
if (c[i] % 100)
{
m -= c[i] % 100;
q.push((node){i});
if (m < 0)
{
int j = q.top().i;
q.pop();
ans += w[j];
m += 100;
f[j] = 1;
}
}
cout << ans << endl;
for (int i = 0; i < n; i++)
{
if (f[i])
printf("%d 0\n", c[i] / 100 + 1);
elseprintf("%d %d\n", c[i] / 100, c[i] % 100);
}
return0;
}