Arquivos
Problem LinkSolution by Mr.Olimpia — 70 pts
Code / Notes
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, B;
cin >> N >> B;
int ans=0; vector<int> bytes(N);
for(int i=0; i<N; i++){
cin >> bytes[i];
}
sort(bytes.begin(), bytes.end());
for(int i=0; i<N; i++){
if(bytes[i]!=0){
for(int j=N-1; j>=i; j--){
if(bytes[j]!=0 && i!=j){
if(bytes[i]+bytes[j]<=B){
ans ++;
bytes[j]=0;
break;
}
}
else if(i==j){
ans++;
bytes[j]==0;
}
}
}
}
cout << ans << endl;
}
Last updated 1 week ago