Submission #72544585


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
const int N=1005,M=50005;
int n,m,p[N],v[N];
long long dp[M],pref[N][M],suff[N][M];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>p[i]>>v[i];
	memset(pref,0,sizeof(pref));
	for(int i=1;i<=n;i++){
		for(int j=0;j<=m;j++){
			pref[i][j]=pref[i-1][j];
			if(j>=p[i])pref[i][j]=max(pref[i][j],pref[i-1][j-p[i]]+v[i]);
		}
	}
	memset(suff,0,sizeof(suff));
	for(int i=n;i>=1;i--){
		for(int j=0;j<=m;j++){
			suff[i][j]=suff[i+1][j];
			if(j>=p[i])suff[i][j]=max(suff[i][j],suff[i+1][j-p[i]]+v[i]);
		}
	}
	
	string ans="";
	long long best=pref[n][m];
	
	for(int i=1;i<=n;i++){
		bool must=false,never=false;
		long long max_without=0;
		for(int j=0;j<=m;j++){
			max_without=max(max_without,pref[i-1][j]+suff[i+1][m-j]);
		}
		
		if(max_without<best){
			must=true;
		}else{
			bool exist_with=false;
			for(int j=0;j<=m-p[i];j++){
				if(pref[i-1][j]+v[i]+suff[i+1][m-j-p[i]]==best){
					exist_with=true;
					break;
				}
			}
			if(!exist_with)never=true;
		}
		
		if(must)ans+='A';
		else if(never)ans+='C';
		else ans+='B';
	}
	
	cout<<ans<<'\n';
	return 0;
}

Submission Info

Submission Time
Task F - Must Buy
User kac17
Language C++23 (GCC 15.2.0)
Score 500
Code Size 1220 Byte
Status AC
Exec Time 493 ms
Memory 788908 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 50
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 338 ms 788768 KiB
example_01.txt AC 368 ms 788892 KiB
hand_00.txt AC 479 ms 788844 KiB
hand_01.txt AC 465 ms 788836 KiB
hand_02.txt AC 462 ms 788828 KiB
hand_03.txt AC 473 ms 788908 KiB
hand_04.txt AC 470 ms 788768 KiB
hand_05.txt AC 378 ms 788832 KiB
hand_06.txt AC 477 ms 788888 KiB
hand_07.txt AC 343 ms 788828 KiB
hand_08.txt AC 479 ms 788848 KiB
hand_09.txt AC 470 ms 788836 KiB
hand_10.txt AC 472 ms 788840 KiB
hand_11.txt AC 459 ms 788832 KiB
hand_12.txt AC 327 ms 788904 KiB
hand_13.txt AC 327 ms 788732 KiB
hand_14.txt AC 331 ms 788704 KiB
hand_15.txt AC 469 ms 788888 KiB
hand_16.txt AC 481 ms 788840 KiB
hand_17.txt AC 486 ms 788908 KiB
random_00.txt AC 477 ms 788888 KiB
random_01.txt AC 474 ms 788728 KiB
random_02.txt AC 476 ms 788828 KiB
random_03.txt AC 335 ms 788684 KiB
random_04.txt AC 334 ms 788728 KiB
random_05.txt AC 366 ms 788888 KiB
random_06.txt AC 359 ms 788684 KiB
random_07.txt AC 399 ms 788896 KiB
random_08.txt AC 397 ms 788728 KiB
random_09.txt AC 465 ms 788856 KiB
random_10.txt AC 470 ms 788832 KiB
random_11.txt AC 469 ms 788732 KiB
random_12.txt AC 488 ms 788684 KiB
random_13.txt AC 487 ms 788728 KiB
random_14.txt AC 487 ms 788768 KiB
random_15.txt AC 471 ms 788888 KiB
random_16.txt AC 475 ms 788728 KiB
random_17.txt AC 492 ms 788832 KiB
random_18.txt AC 487 ms 788732 KiB
random_19.txt AC 484 ms 788840 KiB
random_20.txt AC 483 ms 788876 KiB
random_21.txt AC 482 ms 788796 KiB
random_22.txt AC 486 ms 788908 KiB
random_23.txt AC 469 ms 788876 KiB
random_24.txt AC 473 ms 788840 KiB
random_25.txt AC 478 ms 788828 KiB
random_26.txt AC 479 ms 788768 KiB
random_27.txt AC 491 ms 788728 KiB
random_28.txt AC 491 ms 788840 KiB
random_29.txt AC 493 ms 788876 KiB