#include #include #include #include #include using namespace std; using ll = long long; void Solve( ll& L , list& W , ll& answer ); int main() { ll L; ll N; list W{}; cin >> L; cin >> N; for( ll i = 0 ; i < N ; i++ ){ ll w; cin >> w; W.push_back( w ); } ll answer = 0; Solve( L , W , answer ); cout << answer << endl; return 0; } void Solve( ll& L , list& W , ll& answer ) { bool computing = true; while( computing ){ ll W_min = 0; ll num = 0; list::iterator> W_min_list{}; for( auto itr = W.begin() , end = W.end() ; itr != end ; itr++ ){ const ll& w = *itr; if( W_min == 0 ){ W_min = w; num = 1; W_min_list.push_back( itr ); } else if( W_min == w ){ num++; W_min_list.push_back( itr ); } else if( W_min > w ){ W_min = w; num = 1; W_min_list.clear(); W_min_list.push_back( itr ); } } const ll d = W_min * num; if( L <= d ){ answer += L / W_min; computing = false; } else { L -= d; for( auto itr = W_min_list.begin() , end = W_min_list.end() ; itr != end ; itr++ ){ W.erase( *itr ); } answer += num; } } return; }