Untitled
raw download clone
TEXT
views 9
,
size 661 b
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int c;
    cin >> n >> c;
    int arr[n];
    for(int i=0; i<n; i++){
        cin >> arr[i];
        
    }
    std::vector<int>a;
    for(int i=0; i<n; i++){
       a.push_back(arr[i]);
        }
    std::sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int max=0;
    for(int i=0; i<n*3; i++){
    	
    	if (a[i]<c);
		int sum = a[i];
    	
        for(int j=i+1; j<n-1; j++){
            if ((sum+a[j])<=c){
                sum=sum+a[j];
            }
        }
        if (sum>=max){
            max=sum;
        }
    }
    cout << max;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.