Submission #6133401


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N, x;
    cin >> N >> x;
    int a[N];
    rep(i, N) {
        cin >> a[i];
    }
    sort(a, a+N);
    int ans = 0;

    rep(i, N) {
        if(i == N-1) {
            if(x == a[i]) {
                ans++;
                break;
            }
            break;
        }

        if(x < a[i]) {
            break;
        }
        else if(a[i] <= x) {
            ans++;
            x -= a[i];
        }
    }
    
    cout << ans;
    
    cout << endl;
    return 0;
}

Submission Info

Submission Time
Task A - Candy Distribution Again
User kaguya333
Language C++14 (GCC 5.4.1)
Score 200
Code Size 738 Byte
Status
Exec Time 1 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 200 / 200 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
0_03.txt 1 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 1 ms 256 KB
1_02.txt 1 ms 256 KB
1_03.txt 1 ms 256 KB
1_04.txt 1 ms 256 KB
1_05.txt 1 ms 256 KB
1_06.txt 1 ms 256 KB
1_07.txt 1 ms 256 KB