Submission #67769114


Source Code Expand

// Author: Mkswll
// Date: 2025-07-19 15:24:04
// Problem: D - Get Many Stickers
// Contest: AtCoder - Japan Registry Services (JPRS) Programming Contest 2025#2 (AtCoder Beginner Contest 415)
// URL: https://atcoder.jp/contests/abc415/tasks/abc415_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

// I will become better someday.

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef pair <ld, ld> pdd;
#define debug(x) cout << '[' << #x << ": " << x << "] "
#define cio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases int _; cin >> _; while(_--)
#define pb push_back
#define eb emplace_back
#define space << " " <<
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Unique(v) v.erase(unique(all(v)), v.end())
#define mset(x) memset(x, 0, sizeof(x))
#define sflush fflush(stdout)
#define cflush cout.flush()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define lyes cout << "Yes\n"
#define lno cout << "No\n"
#define nl cout << "\n";
#define vt vector
#define ar array
#define uid uniform_int_distribution 

template <typename T> 
istream& operator >> (istream& in, vector<T>& a){
	for(auto &x : a) in >> x; 
	return in;
}

template <typename T> 
ostream& operator << (ostream& out, vector<T>& a){
	for(auto &x : a) out << x << ' '; 
	return out;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

ll read(){
    int w = 1, c;
    ll ret;
    while((c = getchar()) > '9' || c < '0'){
        w = (c == '-' ? -1 : 1);
    }
    ret = c - '0';
    while((c = getchar()) >= '0' && c <= '9'){
        ret = ret * 10 + c - '0';
    }
    return ret * w;
}

ll rd(){
	ll in;
	cin >> in;
	return in;
}
 
void write(ll x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

const int MAXN = 3e5 + 5, MAXM = 2e5 + 5, INF = 1e9 + 5, MOD = 1e9 + 7;
const ll LMOD = (ll) 1e18 + 9;
const ll LINF = 1e18 + 5;
const ld ep = 1e-8, Pi = acos(-1.0);

ll n, m, k, x; 
pll a[MAXN];
string s;



void clear(){
    
}

int main(){
    cio;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
    	cin >> a[i].F >> a[i].S;
    }
    sort(a + 1, a + m + 1, [](pll x, pll y) {
    	return x.F - x.S < y.F - y.S;
    });
    ll ans = 0;
    for (int i = 1; i <= m; ++i) {
    	ll dif = a[i].F - a[i].S;
    	ll t = max(0ll, n - a[i].F) / dif;
    	ans += t;
    	n -= t * dif;
    	if (n >= a[i].F) {
    		n -= dif;
    		++ans;
    	}
    }
    cout << ans << "\n";
    return 0;
}   

Submission Info

Submission Time
Task D - Get Many Stickers
User Mkswll
Language C++ 20 (gcc 12.2)
Score 400
Code Size 3079 Byte
Status AC
Exec Time 47 ms
Memory 6788 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 3528 KiB
00_sample_01.txt AC 1 ms 3552 KiB
00_sample_02.txt AC 1 ms 3508 KiB
01_random_00.txt AC 24 ms 5040 KiB
01_random_01.txt AC 33 ms 5712 KiB
01_random_02.txt AC 39 ms 6160 KiB
01_random_03.txt AC 29 ms 6712 KiB
01_random_04.txt AC 29 ms 6716 KiB
01_random_05.txt AC 29 ms 6640 KiB
02_random2_00.txt AC 42 ms 6660 KiB
02_random2_01.txt AC 42 ms 6752 KiB
02_random2_02.txt AC 43 ms 6632 KiB
02_random2_03.txt AC 43 ms 6632 KiB
02_random2_04.txt AC 42 ms 6660 KiB
02_random2_05.txt AC 43 ms 6636 KiB
02_random2_06.txt AC 42 ms 6788 KiB
02_random2_07.txt AC 41 ms 6668 KiB
02_random2_08.txt AC 42 ms 6660 KiB
02_random2_09.txt AC 47 ms 6668 KiB
02_random2_10.txt AC 46 ms 6784 KiB
02_random2_11.txt AC 46 ms 6636 KiB
03_random3_00.txt AC 45 ms 6664 KiB
03_random3_01.txt AC 47 ms 6616 KiB
03_random3_02.txt AC 47 ms 6668 KiB
03_random3_03.txt AC 47 ms 6720 KiB
03_random3_04.txt AC 47 ms 6664 KiB
04_handmade_00.txt AC 16 ms 6716 KiB
04_handmade_01.txt AC 16 ms 6716 KiB
04_handmade_02.txt AC 1 ms 3536 KiB
04_handmade_03.txt AC 1 ms 3488 KiB
04_handmade_04.txt AC 37 ms 6664 KiB