B. Doctor
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C . It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
input
Copy
代码语言:javascript复制3 3
1 2 1
output
Copy
代码语言:javascript复制2
input
Copy
代码语言:javascript复制4 10
3 3 2 1
output
Copy
代码语言:javascript复制-1
input
Copy
代码语言:javascript复制7 10
1 3 3 1 2 3 1
output
Copy
代码语言:javascript复制6 2 3
Note
In the first sample test:
- Before examination: {1, 2, 3}
- After the first examination: {2, 3}
- After the second examination: {3, 2}
- After the third examination: {2}
In the second sample test:
- Before examination: {1, 2, 3, 4, 5, 6, 7}
- After the first examination: {2, 3, 4, 5, 6, 7}
- After the second examination: {3, 4, 5, 6, 7, 2}
- After the third examination: {4, 5, 6, 7, 2, 3}
- After the fourth examination: {5, 6, 7, 2, 3}
- After the fifth examination: {6, 7, 2, 3, 5}
- After the sixth examination: {7, 2, 3, 5, 6}
- After the seventh examination: {2, 3, 5, 6}
- After the eighth examination: {3, 5, 6, 2}
- After the ninth examination: {5, 6, 2, 3}
- After the tenth examination: {6, 2, 3}
题意:n只动物去看病,有n个数分别表示这些动物的看病次数,每次医生只能一次看一只动物的病,看完之后这只动物就要到队尾接着排队(如果没看完病的话),问医生K次看病之后的队列情况
思路:无解情况只有一种:所有数的和小于k
有解情况,二分不超过k的最大轮数(轮数是指按顺序扫下去扫到最后一个算一轮结束)然后余数模拟一下就好
代码语言:javascript复制// luogu-judger-enable-o2
#include<bits/stdc .h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 100005
const double eps = 1e-6;
using namespace std;
inline ll read()
{
char ch = getchar(); ll s = 0, w = 1;
while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) { s = (s << 1) (s << 3) (ch ^ 48); ch = getchar(); }
return s * w;
}
inline void write(ll x)
{
if (x < 0)putchar('-'), x = -x;
if (x > 9)write(x / 10);
putchar(x % 10 48);
}
ll n,k,a[2*maxn];
inline bool check(ll x)
{
ll sum=0;
for(rg i=1;i<=n;i )
{
sum =min(a[i],x);
if(sum>k)return 0;
}
if(sum<=k)return 1;
return 0;
}
int main()
{
cin>>n>>k;
ll h=0;
for(rg i=1;i<=n;i )a[i]=read(),h =a[i];
if(h<k)
{
return 0*puts("-1");
}
ll l=0,r=1e14,ans=0;
while(l<=r)
{
ll mid=(l r)>>1;
if(check(mid))l=mid 1,ans=mid;
else r=mid-1;
}
//cout<<ans<<endl;
ll sum=0;
for(rg i=1;i<=n;i )
{
sum =min(a[i],ans);
}
ll mod=k-sum;
for(rg i=1;i<=n;i )
{
a[i]-=min(a[i],ans);
}
if(!mod)
{
for(rg i=1;i<=n;i )
{
if(a[i])cout<<i<<" ";
}
}
else
{
ll cnt=0,temp;
for(rg i=1;i<=n&&cnt<mod;i )
{
if(a[i])
{
a[i]--;
cnt ;
if(cnt==mod)
{
temp=i;
break;
}
}
}
for(rg i=1;i<=n;i )a[i n]=a[i];
for(rg i=temp 1;i<temp 1 n;i )
{
if(a[i])
{
cout<<(i-1)%n 1<<" ";
}
}
}
return 0;
}