Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8.
You can try to decode it yourself by downloading it here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector <pair<long long, unsigned int>> ryby;
void dopisanie();
void usuniecie();
void szczupak();
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >>n;
for (int j=0; j<n; j++){
dopisanie();
} /*mamy wpisane masy pocz�tkowe*/
int q;
cin >>q;
while (q--){
short przypadek;
cin >>przypadek;
switch (przypadek){
cout <<"s";
case 2:
dopisanie();
break;
case 3:
usuniecie();
break;
default: /*(aka case 1) jest to szczupak*/
szczupak();
cout <<'\n';
break;
}
}
return 0;
}
void dopisanie(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long x;
bool czy_jest=false;
cin >>x;
for (unsigned int i=0; i<ryby.size(); i++){
if (ryby[i].first==x){
ryby[i].second++;
czy_jest=true;
}
}
if (czy_jest==false){
ryby.push_back(make_pair(x, 1));
}
}
void usuniecie(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long x;
cin >>x;
for (int i=0; true; i++){
if (x==ryby[i].first){
ryby[i].second--;
break;
}
}
}
void szczupak(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector <pair<long long, unsigned int>> ryby1;
ryby1=ryby;
sort(ryby1.begin(), ryby1.end());
long long s, k;
cin >>s >>k;
int licznik=0;
bool wyk;
while (s<k){
wyk=false;
for (unsigned int i=0; i<ryby1.size(); i++){
if (ryby1[i].first>=s){
wyk=true;
if (i==0){
cout <<"-1";
return;
}
else {
int g=i-1;
while (ryby1[g].second==0){
g--;
if (g==-1){
cout <<"-1";
return;
}
}
s+=ryby1[g].first;
ryby1[g].second--;
licznik++;
break;
}
}
}
if (wyk==false){
int g=ryby.size()-1;
while (ryby1[g].second==0){
g--;
if (g==-1){
cout <<"-1";
return;
}
}
s+=ryby1[g].first;
ryby1[g].second--;
licznik++;
}
}
cout <<licznik;
licznik=0;
}
|