Submission #5493044


Source Code Expand

Copy
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long li;

const int maxn = 100000;

int n, x, a[maxn];

int main(void) {
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  sort(a, a + n);

  int ans = 0;
  for (int i = 0; i < n; ++i) if (a[i] <= x) x -= a[i], ++ans;
  if (ans == n && x) --ans;
  printf("%d\n", ans);
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &x);
                        ^
./Main.cpp:14:49: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 0; i < n; ++i) scanf("%d", a + i);
                                                 ^

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 128 KB
0_01.txt 1 ms 128 KB
0_02.txt 1 ms 128 KB
0_03.txt 1 ms 128 KB
1_00.txt 1 ms 128 KB
1_01.txt 1 ms 128 KB
1_02.txt 1 ms 128 KB
1_03.txt 1 ms 128 KB
1_04.txt 1 ms 128 KB
1_05.txt 1 ms 128 KB
1_06.txt 1 ms 128 KB
1_07.txt 1 ms 128 KB