#include <iostream> #include <math.h> #include <algorithm> #include <cstdio> using namespace std; int tab1 [1000]; int tab2 [1000]; int tab3 [1000]; int main() {ios_base::sync_with_stdio(0); int a,b; cin >> a >> b; int d = b; int e = b; for (int i = 0; i<a; i++) cin >> tab1[i]; for (int i = 0; i<b; i++) {cin >> tab2[i]; tab3[i]=tab2[i];} sort (tab1,tab1 + a); sort (tab2,tab2 + b); sort (tab3,tab3 + b); //cout << tab1[a-1] << " " << tab2[b-1] << endl; int iloscplecakow = 0; for (int c = e-1; c>=0; c--) { for (int i = a-1; i>=0; i--) { if (tab1[i] <= tab2[b-1]) { tab2[b-1] = tab2[b-1] - tab1[i]; tab1[i] = 0; } else b--; } } for (int i = a-1; i>=0; i--) { if (tab1[i]!=0) { cout << "NIE"; return 0; } //cout << tab1[i] << " "; } for (int i = d-1; i>=0; i--) { //cout << tab2[i] << " " << tab3[i] << endl; if (tab2[i]!=tab3[i]) iloscplecakow++; } cout << iloscplecakow; return 0; /* else if (b!=0) { b--; iloscplecakow++; } if (b==0) { cout<<"NIE"; return 0; }*/ }
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 | #include <iostream> #include <math.h> #include <algorithm> #include <cstdio> using namespace std; int tab1 [1000]; int tab2 [1000]; int tab3 [1000]; int main() {ios_base::sync_with_stdio(0); int a,b; cin >> a >> b; int d = b; int e = b; for (int i = 0; i<a; i++) cin >> tab1[i]; for (int i = 0; i<b; i++) {cin >> tab2[i]; tab3[i]=tab2[i];} sort (tab1,tab1 + a); sort (tab2,tab2 + b); sort (tab3,tab3 + b); //cout << tab1[a-1] << " " << tab2[b-1] << endl; int iloscplecakow = 0; for (int c = e-1; c>=0; c--) { for (int i = a-1; i>=0; i--) { if (tab1[i] <= tab2[b-1]) { tab2[b-1] = tab2[b-1] - tab1[i]; tab1[i] = 0; } else b--; } } for (int i = a-1; i>=0; i--) { if (tab1[i]!=0) { cout << "NIE"; return 0; } //cout << tab1[i] << " "; } for (int i = d-1; i>=0; i--) { //cout << tab2[i] << " " << tab3[i] << endl; if (tab2[i]!=tab3[i]) iloscplecakow++; } cout << iloscplecakow; return 0; /* else if (b!=0) { b--; iloscplecakow++; } if (b==0) { cout<<"NIE"; return 0; }*/ } |