답안 #395514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395514 2021-04-28T12:35:56 Z PanTkd Coins (BOI06_coins) C++14
100 / 100
107 ms 13872 KB
//
//  main.cpp
//
//  Created by Panagiotis Chadjicostas on
//  Copyright © Panagiotis Hadjicostas. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define fo(i,a,b) for(int i = a; i<=b; i++)
#define f(i,b) for(int i=0;i<b;i++)
#define F first
#define S second
#define sz size
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
void checker(){
    ll n=rand()%20+2;
    vi a(n,ll());
    for(ll i=0;i<n;i++){
        a[i]=rand()%20+2;
    }
    for(ll b=0;b<(1<<n);b++){
        vi on,off;
        for(ll i=0;i<n;i++){
            if(i&(1<<i)){
                on.push_back(i);
            }
            else{
                off.push_back(i);
            }
        }
    }
}
///////////////////////////////////////////////////////////////////////

struct coin {
    ll v;bool f;
};
void solve(){
    ll n,k;cin>>n>>k;

    coin c[n+2];
    for(ll i=1;i<=n;i++){
        cin>>c[i].v>>c[i].f;
    }
    c[n+1].v=k;c[n+1].f=1;
    ll ans=0,cnt=0;
    for(ll i=1;i<=n;i++){
        if(c[i].f==0 && ans+c[i].v<c[i+1].v){
            ans+=c[i].v;
            cnt++;
        }
    }

    cout<<cnt<< endl << min(k-ans,k-1)<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;//cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 101 ms 13780 KB Output is correct
8 Correct 96 ms 13748 KB Output is correct
9 Correct 107 ms 13872 KB Output is correct
10 Correct 106 ms 13656 KB Output is correct