You are given an array a a a of n n n positive integers and a score. If your score is greater than or equal to a i a_i ai, then you can increase your score by a i a_i ai and remove a i a_i ai from the array.
For each index i i i, output the maximum number of additional array elements that you can remove if you remove a i a_i ai and then set your score to a i a_i ai. Note that the removal of a i a_i ai should not be counted in the answer.
Monocarp is a student at Berland State University. Due to recent changes in the Berland education system, Monocarp has to study only one subject — programming.
The academic term consists of n n n days, and in order not to get expelled, Monocarp has to earn at least P P P points during those n n n days. There are two ways to earn points — completing practical tasks and attending lessons. For each practical task Monocarp fulfills, he earns t t t points, and for each lesson he attends, he earns l l l points.
Practical tasks are unlocked “each week” as the term goes on: the first task is unlocked on day 1 1 1 (and can be completed on any day from 1 1 1 to n n n), the second task is unlocked on day 8 8 8 (and can be completed on any day from 8 8 8 to n n n), the third task is unlocked on day 15 15 15, and so on.
Every day from 1 1 1 to n n n, there is a lesson which can be attended by Monocarp. And every day, Monocarp chooses whether to study or to rest the whole day. When Monocarp decides to study, he attends a lesson and can complete no more than 2 2 2 tasks, which are already unlocked and not completed yet. If Monocarp rests the whole day, he skips a lesson and ignores tasks.
Monocarp wants to have as many days off as possible, i. e. he wants to maximize the number of days he rests. Help him calculate the maximum number of days he can rest!
------------------------独自思考分割线------------------------
------------------------代码分割线------------------------
#include
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
struct Node
{
/* data */
int x, i, f;
};
vector a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i].x;
a[i].i = i;
}
sort(a.begin() + 1, a.end(), [](Node &a, Node &b)
{ return a.x > b.x; });
vector pre(n + 1);
for (int i = 1; i <= n; i++)
pre[i] = pre[i - 1] + a[i].x;
for (int i = 1; i <= n; i++)
if (i == 1)
a[i].f = n - 1;
else
{
if (pre[n] - pre[i - 1] >= a[i - 1].x)
a[i].f = a[i - 1].f;
else
a[i].f = n - i;
}
sort(a.begin(), a.end(), [](Node &a, Node &b)
{ return a.i < b.i; });
for (int i = 1; i <= n; i++)
cout << a[i].f << " ";
cout << endl;
}
// void _()
// {
// int n;
// cin >> n;
// struct Node
// {
// /* data */
// int x, i, res;
// };
// vector a(n + 1);
// for (int i = 1; i <= n; i++)
// {
// cin >> a[i].x;
// a[i].i = i;
// }
// sort(a.begin(), a.end(), [](Node &a, Node &b)
// { return a.x < b.x; });
// vector pre(n + 1);
// for (int i = 1; i <= n; i++)
// pre[i] = pre[i - 1] + a[i].x;
// auto ok = [&](int x)
// {
// return pre[x - 1] >= a[x].x;
// };
// for (int i = 1; i <= n; i++)
// {
// int l = i, r = n + 1;
// while (r - l - 1)
// {
// int mid = l + r >> 1;
// if (ok(mid))
// l = mid;
// else
// r = mid;
// }
// bug2(i, l);
// a[i].res = l - 1;
// }
// sort(a.begin(), a.end(), [](Node &a, Node &b)
// { return a.i < b.i; });
// for (int i = 1; i <= n; i++)
// cout << a[i].res << " ";
// cout << endl;
// }
#include
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, p, t, l;
cin >> n >> p >> l >> t;
auto cal = [](int a, int b)
{
return (a + b - 1) / b;
};
int has = cal(n, 7);
int ned = cal(p, t * 2 + l);
int res = min(has / 2, ned);
p -= res * (t * 2 + l);
// bug(p);
if (p > 0)
{
if (has & 1)
res++, p -= t + l;
}
if (p > 0)
res += cal(p, l);
res = min(res, n);
cout
<< n - res << endl;
}
// void _()
// {
// int n, p, t, l;
// cin >> n >> p >> l >> t;
// auto cal = [](int a, int b)
// {
// return (a + b - 1) / b;
// };
// int has = cal(n, 7);
// int ned = cal(p, t * 2 + l);
// int res = min(has, ned);
// if (ned > has)
// {
// p -= has * (t * 2 + l);
// res += cal(p, l);
// res = min(n, res);
// }
// cout << n - res << endl;
// }