Submission #67723237


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(v) ((int)v.size())
#define fs first
#define sc second
#define all(x) (x.begin()),(x.end())
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pii;

ll n,m;
pii a[200010];
bool cmp(pii& x,pii& y){
	if(x.fs-x.sc!=y.fs-y.sc){
		return x.fs-x.sc<y.fs-y.sc;
	}
	return x.fs<y.fs;
}
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	rep(i,1,m){
		cin>>a[i].fs>>a[i].sc;
	}
	sort(a+1,a+1+m,cmp);
	ll ans=0;
	rep(i,1,m){
		ll t=(n-a[i].fs)/(a[i].fs-a[i].sc)+(n>=a[i].fs);
		if(t>0){
			ans+=t;
			n-=t*(a[i].fs-a[i].sc);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Submission Info

Submission Time
Task D - Get Many Stickers
User friedchicken
Language C++ 20 (gcc 12.2)
Score 400
Code Size 781 Byte
Status AC
Exec Time 55 ms
Memory 6728 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 31
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3452 KiB
00_sample_01.txt AC 1 ms 3392 KiB
00_sample_02.txt AC 1 ms 3336 KiB
01_random_00.txt AC 26 ms 4984 KiB
01_random_01.txt AC 37 ms 5568 KiB
01_random_02.txt AC 44 ms 6016 KiB
01_random_03.txt AC 39 ms 6728 KiB
01_random_04.txt AC 39 ms 6728 KiB
01_random_05.txt AC 39 ms 6456 KiB
02_random2_00.txt AC 49 ms 6588 KiB
02_random2_01.txt AC 49 ms 6456 KiB
02_random2_02.txt AC 48 ms 6600 KiB
02_random2_03.txt AC 48 ms 6528 KiB
02_random2_04.txt AC 47 ms 6572 KiB
02_random2_05.txt AC 48 ms 6656 KiB
02_random2_06.txt AC 49 ms 6728 KiB
02_random2_07.txt AC 49 ms 6576 KiB
02_random2_08.txt AC 49 ms 6652 KiB
02_random2_09.txt AC 53 ms 6604 KiB
02_random2_10.txt AC 53 ms 6532 KiB
02_random2_11.txt AC 53 ms 6668 KiB
03_random3_00.txt AC 55 ms 6728 KiB
03_random3_01.txt AC 53 ms 6600 KiB
03_random3_02.txt AC 53 ms 6640 KiB
03_random3_03.txt AC 53 ms 6588 KiB
03_random3_04.txt AC 52 ms 6588 KiB
04_handmade_00.txt AC 18 ms 6496 KiB
04_handmade_01.txt AC 18 ms 6608 KiB
04_handmade_02.txt AC 1 ms 3544 KiB
04_handmade_03.txt AC 1 ms 3472 KiB
04_handmade_04.txt AC 52 ms 6548 KiB