QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361047 | #8142. Elevator | xianjing | TL | 1ms | 3696kb | C++14 | 1.1kb | 2024-03-22 18:32:28 | 2024-03-22 18:32:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
set<int>c;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
int countLessThanX(int x,const std::set<int>& mySet=c ) {
auto it = mySet.lower_bound(x); // 找到第一个大于或等于 x 的元素的迭代器
return std::distance(mySet.begin(), it);
}
void solve(){
int n,m;
cin>>n>>m;
pair<int,int>a[n];
int b[n+1]={0};
int ans[n];
for(int i=0;i<n;i++){
a[i].first=read();
a[i].second=i;
}
sort(a,a+n);
for(int i=0;i<n;i++){
b[i+1]=b[i]+a[i].first;
}
ans[a[0].second]=0;
for(int i=1;i<n;i++){
ans[a[i].second]=i*a[i].first-b[i]+countLessThanX(a[i].second)+1;
if(ans[a[i].second]>m-2) ans[a[i].second]=-1;
c.insert(a[i].second);
}
for(int i=0;i<n;i++){
cout<<ans[i]<<"\n";
}
return;
}
signed main(){
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3696kb
input:
6 20 3 8 12 6 9 9
output:
0 8 -1 4 13 14
result:
ok 6 lines
Test #2:
score: -100
Time Limit Exceeded
input:
500000 1000000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...