QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370446#4233. ResetInfinityNSTL 6959ms19644kbC++201.9kb2024-03-29 07:52:542024-03-29 07:52:54

Judging History

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

  • [2024-03-29 07:52:54]
  • 评测
  • 测评结果:TL
  • 用时:6959ms
  • 内存:19644kb
  • [2024-03-29 07:52:54]
  • 提交

answer

#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;

const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}


const int maxn=2e5+10;

ll c,n,t[maxn],d[maxn];

using int128=__int128_t;
typedef pair<ll,ll> pll;
bool check(ll mid){

    ll total=min(((int128)mid+1)*min(n,c),(int128)1e18);
    multiset<pair<pll,ll>>st;

    for(int i=1;i<=n;i++){
        st.insert({ {d[i],t[i]},0 });
    }

    ll sum=0;
    ll cpc=c;
    while(st.size() && total>0){

        pair<pll,ll>x=(*st.rbegin());
        st.erase(st.find(x));

        ll d=min(min(total,(ll)x.ff.ss/x.ff.ff), (ll)mid+1-x.ss );

        x.ss+=d;
        x.ff.ss-=d*x.ff.ff;
        total-=d;
        x.ff.ff=min(x.ff.ff,x.ff.ss);

        if(x.ss==mid+1 || x.ff.ss==0){
            sum+=x.ff.ss;
            continue;
        }
        st.insert(x);
    }
    if(total<min(n,c))cpc-=min(n,c)-total;
    while(st.size()){
        sum+=(*st.begin()).ff.ss;
        st.erase(st.begin());
    }

    return sum<=cpc;
}

int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%lld %lld",&n,&c);

    for(int i=1;i<=n;i++){
        scanf("%lld %lld",&t[i],&d[i]);
    }

    //check(249);
    //return 0;

    ll l=0;
    ll r=2e15;
    ll sr,ret=0;
    while(l<=r){
        sr=(l+r)/2;
        if(check(sr)){
            r=sr-1;
            ret=sr;
        }
        else l=sr+1;
    }
    printf("%lld\n",ret);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 5
17 5
5 2
15 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

2 1345
1344 1
10 10

output:

0

result:

ok single line: '0'

Test #3:

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

input:

1 1000000000
1000000000 1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

3 2345
333 1
444 2
555 3

output:

0

result:

ok single line: '0'

Test #5:

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

input:

1 500
1000 2

output:

250

result:

ok single line: '250'

Test #6:

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

input:

1 499
1000 2

output:

250

result:

ok single line: '250'

Test #7:

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

input:

3 2345
3333 5
4444 6
5555 6

output:

646

result:

ok single line: '646'

Test #8:

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

input:

8 6
40 10
40 10
40 10
40 10
40 10
20 5
4 3
5 3

output:

4

result:

ok single line: '4'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3716kb

input:

8 6
40 10
40 10
40 10
40 10
40 10
20 5
7 3
5 3

output:

4

result:

ok single line: '4'

Test #10:

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

input:

5 4
29 8
30 7
2000 1000
2000 1000
2000 1000

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 1ms
memory: 4072kb

input:

27 19
21 5
14 5
14 5
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000

output:

4

result:

ok single line: '4'

Test #12:

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

input:

24 21
25 8
13 7
13 7
13 7
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000

output:

3

result:

ok single line: '3'

Test #13:

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

input:

4 2
10 10
10 10
10 10
9 2

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 1223ms
memory: 12312kb

input:

110000 60000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 10000...

output:

99999

result:

ok single line: '99999'

Test #15:

score: 0
Accepted
time: 2338ms
memory: 19424kb

input:

200000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
10000...

output:

199999999999999

result:

ok single line: '199999999999999'

Test #16:

score: 0
Accepted
time: 6751ms
memory: 19396kb

input:

200000 7
966486041 28
936158040 29
991239679 47
988279269 31
905558493 68
998009820 40
901181342 66
925252807 10
995161072 3
947576761 21
980670741 66
931584704 3
944714227 42
992178536 6
905079737 39
982672468 87
963094272 21
919244645 48
935633595 3
903091417 4
923453539 72
916293313 82
981382022 ...

output:

1405907290168

result:

ok single line: '1405907290168'

Test #17:

score: 0
Accepted
time: 6959ms
memory: 19644kb

input:

200000 313
955333176 37
901868728 50
941539297 29
986447408 44
991503201 16
960466782 13
941404760 26
906572773 27
983407691 42
968036098 75
978785905 2
930572618 67
968054047 14
972769762 39
903513789 23
966791626 84
992080584 65
976672158 15
912399245 35
961103319 25
920979048 64
959902065 72
9685...

output:

31397952846

result:

ok single line: '31397952846'

Test #18:

score: 0
Accepted
time: 5486ms
memory: 19352kb

input:

200000 10
23 21
17 5
5 5
9 2
29 24
14 7
24 23
30 8
10 10
29 27
1 1
3 2
18 7
17 12
26 3
13 6
7 4
28 20
5 1
16 3
24 5
22 4
27 11
11 5
1 1
12 4
1 1
12 3
30 5
26 24
11 9
21 19
1 1
4 4
8 1
29 22
10 8
3 1
24 12
7 7
25 18
11 10
20 19
20 19
20 10
27 26
2 2
12 7
24 18
19 15
19 10
11 4
12 4
2 1
27 9
3 3
19 5
...

output:

70162

result:

ok single line: '70162'

Test #19:

score: 0
Accepted
time: 4950ms
memory: 19384kb

input:

200000 10
4 1
8 4
11 4
15 2
3 3
7 3
14 3
27 4
17 4
4 4
11 5
19 1
29 4
9 5
2 1
30 5
5 1
27 5
20 2
6 5
3 3
30 3
18 2
13 5
16 3
21 3
8 3
17 4
10 5
16 3
8 2
16 3
8 4
4 4
2 2
8 3
30 4
15 1
21 3
19 3
12 5
3 1
23 2
9 3
15 5
4 2
11 3
15 4
5 3
1 1
28 2
12 3
15 3
5 1
6 5
3 1
4 3
18 2
26 4
29 5
7 3
19 2
13 1
1...

output:

147252

result:

ok single line: '147252'

Test #20:

score: 0
Accepted
time: 5687ms
memory: 19436kb

input:

200000 100
18 11
12 3
10 6
28 26
17 2
2 2
6 5
15 12
18 7
26 8
29 18
6 1
20 10
14 4
3 2
3 2
4 2
7 6
7 4
9 2
21 19
11 8
23 19
3 2
10 10
17 12
24 21
12 10
30 22
29 17
12 5
5 4
9 3
20 12
7 6
17 5
5 5
30 4
8 2
29 1
30 25
16 13
25 23
2 1
24 23
10 3
10 10
7 4
24 13
1 1
26 26
3 2
10 3
17 6
14 7
28 18
3 1
17...

output:

7021

result:

ok single line: '7021'

Test #21:

score: 0
Accepted
time: 4773ms
memory: 19376kb

input:

200000 100
3 2
6 3
18 4
14 5
4 1
1 1
25 1
22 1
15 1
2 2
16 2
3 2
11 2
29 4
21 3
13 2
4 1
7 3
13 5
5 2
13 3
19 2
8 3
3 2
22 3
16 1
28 1
26 4
19 3
7 5
22 1
10 3
19 1
5 3
2 2
18 1
5 1
16 2
12 3
20 1
12 5
25 5
20 3
23 2
17 4
30 3
24 1
24 4
16 1
18 1
21 3
9 4
7 5
28 4
1 1
15 2
24 3
1 1
14 1
26 1
27 3
28 ...

output:

14737

result:

ok single line: '14737'

Test #22:

score: 0
Accepted
time: 5419ms
memory: 19396kb

input:

200000 1000
13 1
29 7
22 15
17 12
30 25
20 7
28 12
13 13
8 5
22 7
9 6
20 15
2 2
23 16
13 2
21 1
27 9
1 1
13 5
18 9
28 2
28 8
12 12
10 6
2 2
19 16
4 4
14 14
10 5
7 1
16 16
26 14
5 2
20 12
5 5
3 3
10 7
22 21
7 6
4 3
21 17
22 12
7 5
6 6
17 6
16 6
30 6
22 4
29 16
4 3
29 3
26 17
21 15
21 20
14 13
27 24
1...

output:

698

result:

ok single line: '698'

Test #23:

score: 0
Accepted
time: 4852ms
memory: 19400kb

input:

200000 1000
27 5
2 2
29 4
9 2
16 4
15 3
29 3
1 1
21 2
2 1
21 3
17 4
12 2
26 2
1 1
8 5
29 2
5 3
4 3
9 4
5 5
30 2
11 4
20 5
25 1
22 2
21 1
1 1
5 2
13 4
26 1
5 2
7 3
21 2
27 5
17 3
24 2
25 1
26 4
15 2
5 1
15 5
26 2
6 5
27 4
3 1
19 5
27 4
24 5
3 1
17 4
25 5
1 1
20 2
22 4
12 5
1 1
6 3
25 1
15 1
22 2
10 2...

output:

1474

result:

ok single line: '1474'

Test #24:

score: 0
Accepted
time: 5250ms
memory: 19456kb

input:

200000 998642531
14 6
13 3
2 1
9 6
15 12
10 1
11 9
21 13
23 8
29 8
28 26
1 1
27 5
17 3
14 14
22 11
27 19
5 2
9 3
2 1
11 4
9 3
8 5
28 12
12 7
29 12
19 5
29 16
24 3
20 10
2 2
6 3
9 5
6 4
3 2
18 3
16 3
27 5
14 14
29 23
21 17
22 13
1 1
13 2
21 7
13 1
21 16
11 1
18 8
28 17
14 6
24 8
30 15
29 4
4 2
13 12
...

output:

0

result:

ok single line: '0'

Test #25:

score: -100
Time Limit Exceeded

input:

200000 10
3684 3080
3014 1370
3226 2869
4168 3400
3744 45
4280 670
4898 1215
4699 1387
3103 2201
4357 1267
4602 1765
3290 1180
3556 3370
4198 3434
3743 3324
4592 4451
3328 2499
4848 2244
3879 2853
3676 2630
4758 3917
3057 1758
3045 279
4784 3965
4530 4183
4435 1460
3239 978
4034 269
4046 3652
3626 2...

output:


result: