UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215271#2639. 省钱erican100144ms3720kbC++112.0kb2024-11-27 21:27:132024-11-27 23:39:41

answer


#include <bits/stdc++.h>
#include <queue>
#define rep(l, r, i) for (int i = l, END##i = r; i <= END##i; ++i)
#define per(r, l, i) for (int i = r, END##i = l; i >= END##i; --i)
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define pii pair<int, int>
#define ps second
#define pf first

#define X(j) i[j]
#define Y(j) (dp[j] + (i[j] + L) * (i[j] + L))

#define rd read()
int read() {
    int xx = 0, ff = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
		if (ch == '-')
			ff = -1;
		ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
      xx = xx * 10 + (ch - '0'), ch = getchar();
    return xx * ff;
}
void write(int out) {
	if (out < 0)
		putchar('-'), out = -out;
	if (out > 9)
		write(out / 10);
	putchar(out % 10 + '0');
}

const int N = 3e5 + 5;
const int INF = 1e18;

int n,K,m;
int p[N],c[N];

#define mk make_pair
struct node{
	int c,p;
}e[N];
int cst,cnt,ans;
bool used[N];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >qb,qc;
priority_queue<int,vector<int>,greater<int> >qa;

bool cmp(node x,node y){
	return x.c<y.c;
}
void solve(){
	n=read();K=read();m=read();
	for(int i=1;i<=n;i++)e[i].p=read(),e[i].c=read();
	sort(e+1,e+1+n,cmp);
	for(int i=1;i<=K;i++){
		cst+=e[i].c;
		if(cst>m){
			cout<<i-1<<endl;
      return ;
		}
		qa.push(e[i].p-e[i].c);
	}
	ans=K;
	for(int i=K+1;i<=n;i++){
		qb.push(mk(e[i].p,i));
		qc.push(mk(e[i].c,i));
	}
	for(int i=K+1;i<=n;i++){
		while(used[qb.top().second])qb.pop();
		while(used[qc.top().second])qc.pop(); 
		int costb=qb.top().first;
		int costc=qc.top().first;
		if(costb<=costc+qa.top()){
			cst+=costb;ans++;
			used[qb.top().second]=1;
			qb.pop();
		}
		else{
			qa.push(e[qc.top().second].p-e[qc.top().second].c);
			cst=cst+costc+qa.top();
			used[qc.top().second]=1;
			qa.pop();qc.pop();
		}
		if(cst>m){
			cout<<i-1;return ;
		}
	}
	cout<<n;
}

signed main() {
    int T=1;
    while(T--){
    	solve();
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 9ms
memory: 2200kb

input:

50000 30828 852557364841
682084050 257603011
870868024 517458094
732267860 201407488
777566656 55879...

output:

17903

result:

ok single line: '17903'

Test #2:

score: 10
Accepted
time: 19ms
memory: 3544kb

input:

50000 10508 8982273367520
34111224 12372852
549875017 525549262
357107918 219952140
644308048 222008...

output:

37621

result:

ok single line: '37621'

Test #3:

score: 10
Accepted
time: 13ms
memory: 2136kb

input:

50000 23114 535861686266
359271294 298114231
605400720 491693949
755566780 539381575
155586610 92962...

output:

14723

result:

ok single line: '14723'

Test #4:

score: 10
Accepted
time: 21ms
memory: 3568kb

input:

50000 13490 4616703243118
286358449 133228996
162995754 17235506
661390160 561824344
282751480 15433...

output:

30961

result:

ok single line: '30961'

Test #5:

score: 10
Accepted
time: 19ms
memory: 3164kb

input:

50000 26352 8630976119100
70133466 32927792
90392510 89764542
307782646 75889114
123168574 66039130
...

output:

42944

result:

ok single line: '42944'

Test #6:

score: 10
Accepted
time: 13ms
memory: 2132kb

input:

50000 11800 213255455323
405512104 311547645
122797690 35257030
782246460 533338866
416860264 504733...

output:

9869

result:

ok single line: '9869'

Test #7:

score: 10
Accepted
time: 11ms
memory: 3376kb

input:

50000 19734 4267681411347
732638120 327229436
361949068 274173372
539440696 285784669
94445920 84513...

output:

32498

result:

ok single line: '32498'

Test #8:

score: 10
Accepted
time: 7ms
memory: 3708kb

input:

50000 254 18445304121
375481124 36148026
388507104 183081259
261838134 179691990
485282800 209534680...

output:

1564

result:

ok single line: '1564'

Test #9:

score: 10
Accepted
time: 19ms
memory: 3720kb

input:

50000 3260 4076050769242
210627773 8756794
68253913 5333287
812306900 176444281
561388618 94960450
6...

output:

23173

result:

ok single line: '23173'

Test #10:

score: 10
Accepted
time: 13ms
memory: 2588kb

input:

50000 44485 12129791734731
590854222 262410600
992399148 641692708
219274382 56485932
730651726 4088...

output:

49537

result:

ok single line: '49537'