Submission #3198946


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;
#define INF 2001001001
#define MOD 1000000007
typedef long long ll;

ll N,X;
ll arr[101];

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  cin>>N>>X;
  for (int i=0;i<N;i++)
    cin>>arr[i];
  sort(arr,arr+N);
  ll ans=0;
  for (int i=0;i<N;i++)
    if (X-arr[i]>=0){
      X-=arr[i];
      ans++;
    }
  if (X>0)
    ans--;
  ans=max(ans,0);
  cout<<ans<<endl;
  return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:16: error: no matching function for call to ‘max(ll&, int)’
   ans=max(ans,0);
                ^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from ./Main.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/5/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
./Main.cpp:33:16: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
   ans=max(ans,0);
                ^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                ...