#include "krazki.h" #include "message.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { if (MyNodeId() == 0) { int n, m; n = PipeHeight(); m = NumberOfDiscs(); //cin >> n >> m; vector<long long>rurka(n + 1);//glebokosc minn rurka[0] = HoleDiameter(1ll); //cin >> rurka[0]; for (long long i = 1; i < n; i++) { rurka[i] = HoleDiameter(i + 1); //cin >> rurka[i]; rurka[i] = min(rurka[i], rurka[i - 1]); } long long last = n; bool bylo = false; for (long long i = 0; i < m; ++i) { long long krazek, v = last - 1; krazek = DiscDiameter(i + 1); //cin >> krazek; while (v > 0 && rurka[v] < krazek) { v--; } last = v; if (last == 0) { cout << 0 << "\n"; bylo = true; } } if (!bylo) cout << last + 1 << "\n"; } }
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 | #include "krazki.h" #include "message.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { if (MyNodeId() == 0) { int n, m; n = PipeHeight(); m = NumberOfDiscs(); //cin >> n >> m; vector<long long>rurka(n + 1);//glebokosc minn rurka[0] = HoleDiameter(1ll); //cin >> rurka[0]; for (long long i = 1; i < n; i++) { rurka[i] = HoleDiameter(i + 1); //cin >> rurka[i]; rurka[i] = min(rurka[i], rurka[i - 1]); } long long last = n; bool bylo = false; for (long long i = 0; i < m; ++i) { long long krazek, v = last - 1; krazek = DiscDiameter(i + 1); //cin >> krazek; while (v > 0 && rurka[v] < krazek) { v--; } last = v; if (last == 0) { cout << 0 << "\n"; bylo = true; } } if (!bylo) cout << last + 1 << "\n"; } } |