Submission #3198712


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload4(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl


int main(){
    int n,x;
    cin>>n>>x;
    vi a(n);
    REP(i,n){
        cin>>a[i];
    }
    sort(all(a));
    int ans=0;
    REPARR(i,a){
        if(a[i]<=x){
            x-=a[i];
            ans++;
        }else{
            break;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Submission Info

Submission Time
Task A - Candy Distribution Again
User ibuki2003
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1611 Byte
Status

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:38:9: error: ‘i’ was not declared in this scope
     REP(i,n){
         ^
./Main.cpp:18:29: note: in definition of macro ‘REP’
 #define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
                             ^
./Main.cpp:18:41: error: ‘_repis’ was not declared in this scope
 #define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
                                         ^
./Main.cpp:38:5: note: in expansion of macro ‘REP’
     REP(i,n){
     ^
./Main.cpp:18:48: error: ‘_repi’ was not declared in this scope
 #define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
                                                ^
./Main.cpp:38:5: note: in expansion of macro ‘REP’
     REP(i,n){
     ^
./Main.cpp:18:54: error: ‘_rep’ was not declared in this scope
 #define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
                                                      ^
./Main.cpp:38:5: note: in e...