Submission #68325769
Source Code Expand
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
int read(){int f=0,x=0;char a=getchar();while(!isdigit(a)){if(a=='-')f=1;a=getchar();}while(isdigit(a)){x=x*10+a-'0';a=getchar();}if(f)return -x;return x;}
int main()
{
//freopen(in.in,r,stdin);
//freopen(out.out,w,stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int tttt=1;
//cin>>tttt;
while(tttt--)
{
ll n,q;cin>>n>>q;
vector<ll>a(n+1),he(n+1,0);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a.begin()+1,a.end());
for(int i=1;i<=n;i++)
{
he[i]=he[i-1]+a[i];
}
while(q--)
{
ll b;cin>>b;
if(b>a[n])
{
cout<<"-1\n";
continue;
}
ll i=lower_bound(a.begin()+1,a.end(),b)-a.begin();
//cout<<i<<'\n';
cout<<he[i-1]+(b-1)*(n-i+1)+1<<'\n';
}
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Flush |
| User | evilwater |
| Language | C++ 23 (gcc 12.2) |
| Score | 350 |
| Code Size | 1027 Byte |
| Status | AC |
| Exec Time | 103 ms |
| Memory | 9016 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 3532 KiB |
| 00-sample-02.txt | AC | 1 ms | 3600 KiB |
| 01-01.txt | AC | 4 ms | 3404 KiB |
| 01-02.txt | AC | 4 ms | 3536 KiB |
| 01-03.txt | AC | 4 ms | 3364 KiB |
| 01-04.txt | AC | 103 ms | 8880 KiB |
| 01-05.txt | AC | 41 ms | 7736 KiB |
| 01-06.txt | AC | 61 ms | 8868 KiB |
| 01-07.txt | AC | 75 ms | 9016 KiB |
| 01-08.txt | AC | 67 ms | 8872 KiB |
| 01-09.txt | AC | 98 ms | 8352 KiB |