UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215229#2639. 省钱nullptr_qwq100530ms10340kbC++115.3kb2024-11-27 18:46:502024-11-27 23:36:09

answer

// 私は猫です

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<typename T>inline void chkmax(T &x,const T &y){ x=std::max(x,y); }
template<typename T>inline void chkmin(T &x,const T &y){ x=std::min(x,y); }
const int mod=998244353,maxn=500005;
int n,k,t,a[maxn],b[maxn];
multiset<pii>A,B;
multiset<int>st;
bool vis[maxn];
void solve(){
	cin>>n>>k>>t;
	F(i,1,n)cin>>a[i]>>b[i],A.insert(mkp(a[i],i)),B.insert(mkp(b[i],i));
	F(i,1,k)st.insert(0);
	int ans=0;
	while(!A.empty()){
		auto it1=A.begin(),it2=B.begin();
		auto it3=st.begin();
		const int x=it1->second,y=it2->second,val=*it3;
		if(vis[x]){ A.erase(it1); continue; }
		if(vis[y]){ B.erase(it2); continue; }
		if(val+b[y]>a[x])t-=a[x],A.erase(it1),vis[x]=1;
		else{
			t-=(b[y]+val),B.erase(it2),st.erase(it3),vis[y]=1;
			st.insert(a[y]-b[y]);
		}
		if(t<0)break;
		++ans;
	}
	cout<<ans;
}
signed main(){
	const int zsy=1;
	F(____,1,zsy)solve();
}

Details

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

Test #1:

score: 10
Accepted
time: 53ms
memory: 9700kb

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: 55ms
memory: 8748kb

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: 49ms
memory: 9340kb

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: 52ms
memory: 8888kb

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: 59ms
memory: 9496kb

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: 50ms
memory: 8808kb

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: 59ms
memory: 9180kb

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: 43ms
memory: 8268kb

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: 43ms
memory: 8408kb

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: 67ms
memory: 10340kb

input:

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

output:

49537

result:

ok single line: '49537'