?
№ | Отправитель | Задача | Язык | Вердикт | Время | Память | Отослано | Протест. | |
---|---|---|---|---|---|---|---|---|---|
236650503 |
Дорешивание: sshreyansh962 |
158B - 10 | C++17 (GCC 7-32) | Неправильный ответ на тесте 1 | 0 мс | 0 КБ | 2023-12-10 14:50:30 | 2023-12-10 14:50:30 |
#include<iostream> using namespace std; int main(){ int n; cin>>n; int arr[n]; int ones=0; int threes=0; int twos=0; int sum=0; for(int i=0;i<n;i++){ cin>>arr[i]; if(arr[i]==1){ ones++; } else if(arr[i]==3){ threes++; } else if(arr[i]==4){ sum++; } else if(arr[i]==2){ twos++; } } int pair_of_3_1; if(ones!=0 && threes!=0){ if(ones==threes){ pair_of_3_1=ones; } else{ if(ones>threes){ pair_of_3_1=threes; ones-=threes; } else{ pair_of_3_1=ones; threes-=ones; } } } sum+=pair_of_3_1; if(twos!=0 && twos%2==0){ sum+=twos/2; twos=0; } else{ sum+=twos/2; twos=1; } if(ones>0){ if(ones>=2){ ones-=2; twos=0; sum+=1; if(ones>0){ sum=sum+ones%4 +ones/4 ; } } } else if(threes>0){ sum+=threes; } else if(twos>0){ sum+=1; } cout<<sum; }
?
?
?
?