QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#46520#4202. Even ElectricityMoQzWA 29ms5380kbC++989b2022-08-30 10:04:382022-08-30 10:04:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-30 10:04:38]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:5380kb
  • [2022-08-30 10:04:38]
  • 提交

answer

#include<iostream>
#include<cstdio>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
int read(){
	int u=0;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
	while(c>='0'&&c<='9')u=u*10+c-48,c=getchar();
	return u;
}
int n;
long long r2;
long long s[200011],w[200011];
bool solve_l(long long l){
	long long R=0;
	fo(i,1,n){
		R=min(R+w[i],min(r2,R+w[i]-l+s[i]));
		if(R<0)return 0;
	}
	return 1;
}
bool solve_r(long long r){
	long long L=0;
	fo(i,1,n){
		L=L+w[i]-r+s[i];
		if(L<0)L=0;
		if(L>r2||(i==n&&L>0))return 0;
	}
	return 1;
}
int main(){
	n=read();
	r2=read();
	fo(i,1,n){
		s[i]=read();
		w[i]=read();
	}
	long long ans=0;
	long long l=0,r=1999999999,mid;
	while(l<r){
		mid=(l+r+1)/2;
		if(solve_l(mid))l=mid;
		else r=mid-1;
	}
	ans-=l;
	l=0,r=1999999999,mid;
	while(l<r){
		mid=(l+r)/2;
		if(solve_r(mid))r=mid;
		else l=mid+1;
	}
	printf("%lld",ans+r);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3660kb

input:

3 1
4 2
2 0
5 1

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

1 10
10 9

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3728kb

input:

2 10
6 10
9 6

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3724kb

input:

10 10
5 6
8 0
1 8
2 2
7 5
5 3
10 6
3 0
9 2
0 9

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3732kb

input:

10 10
6 1
9 1
8 10
2 5
8 10
6 10
10 9
4 8
0 1
0 6

output:

8

result:

ok single line: '8'

Test #6:

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

input:

10 10
4 9
4 3
2 2
10 7
6 9
3 5
5 8
7 4
0 4
8 2

output:

4

result:

ok single line: '4'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

10 10
6 7
5 0
5 9
9 6
2 2
0 3
2 10
4 8
1 6
2 9

output:

3

result:

ok single line: '3'

Test #8:

score: 0
Accepted
time: 25ms
memory: 5232kb

input:

100000 1000000000
413794426 487008076
857157934 416640558
335458362 938175747
331906268 815014691
884031347 954760972
747185588 109876528
795877270 347023646
687257733 17478773
649166691 883831823
683020200 450159267
250807459 945914456
375003437 674695585
585101823 862146285
765383066 602155570
285...

output:

1105061946

result:

ok single line: '1105061946'

Test #9:

score: 0
Accepted
time: 16ms
memory: 5220kb

input:

100000 1000000000
242077119 729724206
279044101 368837879
376881006 400928995
600291353 3398737
105837927 606968424
653114466 280439694
433127753 705813398
797330526 591799335
606747464 851192297
380825730 999336566
777818898 881558226
809144711 326167836
160650518 862351925
375940812 290070875
9581...

output:

1108081577

result:

ok single line: '1108081577'

Test #10:

score: 0
Accepted
time: 21ms
memory: 5252kb

input:

100000 1000000000
526097939 341763432
847150260 539385269
151198061 965181383
438329724 395601548
471761451 786498213
589692967 79420741
142047807 559437448
318348321 347781041
38687331 751499909
190623797 71750463
450528748 259219077
159485005 605128044
398566472 960935290
179478648 715733784
74058...

output:

1213605526

result:

ok single line: '1213605526'

Test #11:

score: 0
Accepted
time: 29ms
memory: 5308kb

input:

100000 1000000000
13201362 688008764
471723115 550879412
502385021 492967970
993776412 215495923
418646 441134117
899775024 717798730
796833224 937450002
578442539 977818344
744756004 540294838
446872174 592857446
341630081 64488239
352740110 758135828
262962096 403487879
207124761 260936746
1257939...

output:

1127515141

result:

ok single line: '1127515141'

Test #12:

score: 0
Accepted
time: 11ms
memory: 5260kb

input:

100000 10
9 8
3 10
10 4
1 6
2 3
4 4
3 6
10 10
3 8
6 2
4 9
4 8
7 0
6 6
0 9
8 8
5 6
10 2
2 3
10 8
5 8
8 7
9 6
6 7
7 2
6 6
10 9
2 3
8 10
1 0
5 5
7 8
0 10
4 5
0 1
6 9
6 3
3 4
6 1
4 10
3 6
8 4
2 8
0 7
4 0
4 1
0 0
8 10
9 2
7 9
2 1
7 0
8 5
5 3
0 4
4 1
6 0
6 3
9 1
9 10
1 6
2 6
10 10
8 4
0 8
10 10
5 8
2 0
0 ...

output:

14

result:

ok single line: '14'

Test #13:

score: 0
Accepted
time: 7ms
memory: 5332kb

input:

100000 1000000000
0 12
0 8
0 6
0 9
0 12
0 9
0 17
0 8
0 7
0 7
0 11
0 8
0 8
0 14
0 6
0 6
0 6
0 13
0 5
0 7
0 10
0 8
0 11
0 6
0 5
0 9
0 11
0 13
0 8
0 6
0 8
0 9
0 9
0 4
0 9
0 5
0 11
0 14
0 10
0 8
0 12
0 7
0 7
0 3
0 9
0 9
0 8
0 3
0 7
0 9
0 11
0 7
0 12
0 11
0 10
0 4
0 8
0 8
0 12
0 3
0 5
0 6
0 4
0 9
0 3
0 9...

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 3ms
memory: 5288kb

input:

100000 1000000000
0 12
0 8
0 6
0 9
0 12
0 9
0 17
0 8
0 7
0 7
0 11
0 8
0 8
0 14
0 6
0 6
0 6
0 13
0 5
0 7
0 10
0 8
0 11
0 6
0 5
0 9
0 11
0 13
0 8
0 6
0 8
0 9
0 9
0 4
0 9
0 5
0 11
0 14
0 10
0 8
0 12
0 7
0 7
0 3
0 9
0 9
0 8
0 3
0 7
0 9
0 11
0 7
0 12
0 11
0 10
0 4
0 8
0 8
0 12
0 3
0 5
0 6
0 4
0 9
0 3
0 9...

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 12ms
memory: 5236kb

input:

100000 1000000000
1000000000 10012
1000000000 10008
1000000000 10006
1000000000 10009
1000000000 10012
1000000000 10009
1000000000 10017
1000000000 10008
1000000000 10007
1000000000 10007
1000000000 10011
1000000000 10008
1000000000 10008
1000000000 10014
1000000000 10006
1000000000 10006
1000000000...

output:

0

result:

ok single line: '0'

Test #16:

score: 0
Accepted
time: 22ms
memory: 5328kb

input:

100000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000...

output:

0

result:

ok single line: '0'

Test #17:

score: -100
Wrong Answer
time: 24ms
memory: 5380kb

input:

100000 1
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
10000...

output:

14

result:

wrong answer 1st lines differ - expected: '15', found: '14'