Submission #68325531
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pi pair<int, int>
#define mp make_pair
#define vi vector<int>
#define vvi vector<vector<int>>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int INF = (int)4e18;
const int MODa = 1e9 + 7;
const int MOD = 998244353;
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
void solve()
{
int n, q;
cin>>n>>q;
vector<int> a(n+1, 0);
for(int i=1; i<=n; i++)
{
cin>>a[i];
}
sort(a.begin()+1, a.end());
vector<int> p(n+1, 0);
for(int i=1; i<=n; i++)
{
p[i] = p[i-1] + a[i];
}
for(int i=1; i<=q; i++)
{
int b;
cin>>b;
auto it = lower_bound(a.begin()+1, a.end(), b);
if(it==a.end())
{
cout<<-1<<"\n";
continue;
}
int x = (it-a.begin());
int ans = p[x-1] + (b-1)*(n-x+1) + 1;
cout<<ans<<"\n";
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin>>t;
while(t--)
{
solve();
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Flush |
| User | ha___il |
| Language | C++ 20 (gcc 12.2) |
| Score | 350 |
| Code Size | 1321 Byte |
| Status | AC |
| Exec Time | 107 ms |
| Memory | 9084 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 | 3464 KiB |
| 00-sample-02.txt | AC | 1 ms | 3484 KiB |
| 01-01.txt | AC | 5 ms | 3608 KiB |
| 01-02.txt | AC | 5 ms | 3488 KiB |
| 01-03.txt | AC | 5 ms | 3480 KiB |
| 01-04.txt | AC | 107 ms | 8920 KiB |
| 01-05.txt | AC | 52 ms | 7808 KiB |
| 01-06.txt | AC | 64 ms | 8844 KiB |
| 01-07.txt | AC | 78 ms | 9084 KiB |
| 01-08.txt | AC | 70 ms | 8828 KiB |
| 01-09.txt | AC | 102 ms | 8312 KiB |