#include<iostream> #include<algorithm> using namespace std; //********************************************************************************************************************************************* long long klijent[200000], piekarnik[1000000],roznice[200001],minimum = 10000000000000; //********************************************************************************************************************************************* int main() { ios::sync_with_stdio(false); int k, p, potega, pytanie; long long suma_minusow = 0; long long minus = 0; long long wynik = 0; cin >> k >> p; for (int i = 0; i < k; i++) { cin >> klijent[i]; if (i > 0) { roznice[i] = klijent[i] - klijent[i - 1]; } } roznice[0] = klijent[0]; for (int i = 1; i <= 1000000; i++) { wynik = 0; minimum = 10000000000000; for (int j = 0; j < k; j++) { roznice[j] = roznice[j] - 1 - minus; if (roznice[j] < 0) { wynik -= roznice[j]; minus++; suma_minusow+=minus; } else { minimum = min(minimum, roznice[j] / (minus + 1)); minus = 0; } } piekarnik[i] = wynik; if (minus == k) { for (int j = i + 1; j <= 1000000; j++) { piekarnik[j] = piekarnik[j-1] + suma_minusow; } break; } int j; if (i + 1 + minimum > 1000000) { minimum = 1000000 - i - 1; } for ( j = i + 1; j < i + minimum; j++) { piekarnik[j] = piekarnik[j - 1] + suma_minusow; } i = j - 1; wynik = 0; minus = 0; suma_minusow = 0; } for (int i = 0; i < p; i++) { cin >> pytanie; cout << piekarnik[pytanie] << endl; } system("pause"); } //*********************************************************************************************************************************************
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 | #include<iostream> #include<algorithm> using namespace std; //********************************************************************************************************************************************* long long klijent[200000], piekarnik[1000000],roznice[200001],minimum = 10000000000000; //********************************************************************************************************************************************* int main() { ios::sync_with_stdio(false); int k, p, potega, pytanie; long long suma_minusow = 0; long long minus = 0; long long wynik = 0; cin >> k >> p; for (int i = 0; i < k; i++) { cin >> klijent[i]; if (i > 0) { roznice[i] = klijent[i] - klijent[i - 1]; } } roznice[0] = klijent[0]; for (int i = 1; i <= 1000000; i++) { wynik = 0; minimum = 10000000000000; for (int j = 0; j < k; j++) { roznice[j] = roznice[j] - 1 - minus; if (roznice[j] < 0) { wynik -= roznice[j]; minus++; suma_minusow+=minus; } else { minimum = min(minimum, roznice[j] / (minus + 1)); minus = 0; } } piekarnik[i] = wynik; if (minus == k) { for (int j = i + 1; j <= 1000000; j++) { piekarnik[j] = piekarnik[j-1] + suma_minusow; } break; } int j; if (i + 1 + minimum > 1000000) { minimum = 1000000 - i - 1; } for ( j = i + 1; j < i + minimum; j++) { piekarnik[j] = piekarnik[j - 1] + suma_minusow; } i = j - 1; wynik = 0; minus = 0; suma_minusow = 0; } for (int i = 0; i < p; i++) { cin >> pytanie; cout << piekarnik[pytanie] << endl; } system("pause"); } //********************************************************************************************************************************************* |