QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338264#1177. BookfaceWRuperDAC ✓158ms9436kbC++201.0kb2024-02-25 19:48:222024-02-25 19:48:22

Judging History

你现在查看的是最新测评结果

  • [2024-02-25 19:48:22]
  • 评测
  • 测评结果:AC
  • 用时:158ms
  • 内存:9436kb
  • [2024-02-25 19:48:22]
  • 提交

answer

// Problem: A. 【PR #12】电塔
// URL: https://pjudge.ac/contest/1526/problem/21807
// Writer: WRuperD
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define int long long
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<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 1e6 + 10;
int a[MAX];
void solve(){
	int n = read(), d = read();
	for(int i = 1; i <= n; i++)	a[i] = read();
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++)	a[i] -= d * (i - 1);
	priority_queue <int> q;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int x = a[i];
		q.push(x);
		if(x <= q.top()){
			ans += q.top() - x;
			q.pop();
			q.push(x > 0 ? x : 0);
		}
	}
	write(ans), endl;
}
 
signed main(){
	int t = read();
	while(t--)	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

2
4 1
0 0 0 0
4 10
1 100 5 10

output:

6
16

result:

ok 2 number(s): "6 16"

Test #2:

score: 0
Accepted
time: 23ms
memory: 3792kb

input:

98280
7 8
299 294 297 292 293 290 289
7 7
11 7 9 2 6 4 0
6 2
295 296 288 292 289 290
8 7
294 298 295 290 292 293 297 291
8 8
292 299 290 293 296 288 298 295
8 4
290 288 298 295 299 289 296 292
4 4
10 2 0 7
4 2
291 298 297 299
5 6
296 288 298 299 293
5 10
290 294 295 293 296
8 11
0 11 4 8 10 5 2 9
4 ...

output:

77
108
4
94
103
35
5
2
20
52
259
35
50
100
66
21
47
64
92
91
104
45
13
61
31
12
62
4
0
35
12
72
79
5
135
100
149
58
126
193
8
104
0
41
18
21
88
0
10
69
2
0
87
2
8
82
51
198
1
2
145
21
102
7
0
106
0
111
41
18
39
129
2
99
20
19
23
18
12
7
29
52
24
0
49
91
74
14
37
152
17
54
60
88
14
0
34
14
8
41
25
20...

result:

ok 98280 numbers

Test #3:

score: 0
Accepted
time: 115ms
memory: 3664kb

input:

669
1703 762924
873022128 300066207 1206419913 1269742605 1079774532 85684564 320665155 546490659 547253583 55167604 828772536 306169599 950840376 790626336 146718484 475538727 1200316521 595317794 1025606928 794440956 243609831 1233122253 566326683 808173588 569378379 989749500 1294919097 716622708...

output:

3253
458301850
79
80535
235992546
48759003
306315842
128083532
332544825
14768472
3771
385408117
125880821
251912220
378698670
22018229
2248
10203802
247102873
2556
3659
182576709
387349688
254103271
3989
78877516
276786211
132052865
318642737
2674
3340
180128422
521438360
349874364
491202128
299606...

result:

ok 669 numbers

Test #4:

score: 0
Accepted
time: 158ms
memory: 9436kb

input:

5
200000 733779
5361989373 113163663523 99233602998 108403639154 58100887401 120013490484 71790268408 126920552205 111792230572 115622556950 38382044346 137127418089 117789406336 93700909340 140037585603 122991899442 97647906580 114932070911 64487699812 12479645668 97811539297 59197887004 3165035581...

output:

5227485
16167521795
10000000000
34035608352
36804

result:

ok 5 number(s): "5227485 16167521795 10000000000 34035608352 36804"