Submission #32387176
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXn = 2e5;
template <typename T>
inline void read(T &a) {
char c;for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar());bool f = c == '-';T x = f ? 0 : (c ^ '0');for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) {x = x * 10 + (c ^ '0');}a = f ? -x : x;
}
template <typename T, typename ...Argv>
inline void read(T &a, Argv &...argv) {
read(a), read(argv...);
}
int n, q;
int a[MAXn + 10];
int suma[MAXn + 10];
inline int Dic(int x) {
int L = 1, R = n, M;
while (L < R) {
M = (L + R + 1) >> 1;
if (a[M] <= x) L = M;
else R = M - 1;
}
if (a[L] <= x) return L;
else return 0;
}
signed main() {
read(n, q);
for (int i = 1; i <= n; ++i) {
read(a[i]);
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; ++i) {
suma[i] = suma[i - 1] + a[i];
}
for (int i = 1, x; i <= q; ++i) {
read(x);
int p = Dic(x);
printf("%lld\n", x * p - suma[p] + (suma[n] - suma[p]) - x * (n - p));
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - ±1 Operation 2 |
| User | rsdbk_husky_undo |
| Language | C++ (GCC 9.2.1) |
| Score | 400 |
| Code Size | 1057 Byte |
| Status | AC |
| Exec Time | 91 ms |
| Memory | 6868 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | sample_01.txt, sample_02.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 7 ms | 3496 KiB |
| sample_02.txt | AC | 2 ms | 3692 KiB |
| test_01.txt | AC | 3 ms | 3692 KiB |
| test_02.txt | AC | 2 ms | 3552 KiB |
| test_03.txt | AC | 48 ms | 6628 KiB |
| test_04.txt | AC | 37 ms | 4800 KiB |
| test_05.txt | AC | 29 ms | 4012 KiB |
| test_06.txt | AC | 67 ms | 6268 KiB |
| test_07.txt | AC | 65 ms | 6408 KiB |
| test_08.txt | AC | 56 ms | 5184 KiB |
| test_09.txt | AC | 55 ms | 5052 KiB |
| test_10.txt | AC | 82 ms | 6748 KiB |
| test_11.txt | AC | 80 ms | 6720 KiB |
| test_12.txt | AC | 84 ms | 6724 KiB |
| test_13.txt | AC | 81 ms | 6560 KiB |
| test_14.txt | AC | 83 ms | 6612 KiB |
| test_15.txt | AC | 91 ms | 6752 KiB |
| test_16.txt | AC | 82 ms | 6868 KiB |
| test_17.txt | AC | 48 ms | 6752 KiB |
| test_18.txt | AC | 54 ms | 6556 KiB |