Submission #1155424


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


typedef long long ll;
#define inf INT_MAX/2
int N, Q, X[101010], T[101010];
ll sm[101010];
//-----------------------------------------------------------------
int main() {
	cin >> N >> Q;
	rep(i, 0, N) scanf("%d", &X[i]);
	rep(i, 0, Q) scanf("%d", &T[i]);

	sort(X, X + N);
	sm[0] = X[0];
	rep(i, 1, N) sm[i] = sm[i - 1] + X[i];

	rep(i, 0, Q) {
		int j = lower_bound(X, X + N, T[i]) - X;

		ll ans = 0;
		if (j == N)
			ans = 1LL * T[i] * N - sm[N - 1];
		else if (j == 0)
			ans = sm[N - 1] - 1LL * T[i] * N;
		else {
			ans = (1LL * T[i] * j - sm[j - 1]) + ((sm[N - 1] - sm[j - 1]) - 1LL * T[i] * (N - j));
		}

		printf("%lld\n", ans);
	}
}

Submission Info

Submission Time
Task D - 数直線
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 764 Byte
Status AC
Exec Time 52 ms
Memory 3328 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i, 0, N) scanf("%d", &X[i]);
                                 ^
./Main.cpp:14:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i, 0, Q) scanf("%d", &T[i]);
                                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 10
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
01.txt AC 3 ms 384 KB
02.txt AC 51 ms 3328 KB
03.txt AC 51 ms 3328 KB
04.txt AC 52 ms 3328 KB
05.txt AC 51 ms 3328 KB
06.txt AC 51 ms 3328 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB