#include #define ll long long #define Epsilon 1e-5 using namespace std; mt19937_64 rng; clock_t BEGIN; clock_t END; ///Input: int N; ll B; ///Sticks: struct STICK { ll h; //height of the stick ll p; //penalty of the stick int i; //initial index of the stick }STICKS[1000096]; struct DIRECT { ll h; ll p; }DSTICKS[1000096]; struct LOCATION { int k; int d; }LOCATIONS[1000096]; int PERMSTICKS[1096]; ///Holes: struct HOLE { int d; //number of sticks inside the hole vector Sticks; //indices of sticks inside of the hole ll h; //height of sticks inside the hole ll p; //penalty got for the hole }HOLES[1000096], HOLESFINAL[1000096]; ll KC, K; //KC is the current number of holes used, K is the final number of holes used ll SCOREC, SCORE; //SCOREC is the current SCORE, SCOREP is the permutation SCORE, SCORE is the final score inline void PrintSTICKS() { printf("\nHeight:\t"); for(int i = 1; i <= N; i++) { printf(" %lld", STICKS[i].h); } printf(";\nPenalty:\t"); for(int i = 1; i <= N; i++) { printf(" %lld", STICKS[i].p); } printf(";\nIndices:\t"); for(int i = 1; i <= N; i++) { printf(" %d", STICKS[i].i); } printf(";\n"); return; } inline void PrintHOLES() { printf("\nHeight:\t\t"); for(int i = 1; i <= N; i++) { printf(" %lld", HOLES[i].h); } printf(";\nPenalty:\t\t"); for(int i = 1; i <= N; i++) { printf(" %lld", HOLES[i].p); } printf(";\n"); return; } inline void SetInitialScore() { SCORE = 2e18 + 1; return; } inline void CalculateHolePenalty() { for(int i = 1; i <= KC; i++) { if(HOLES[i].h > B) HOLES[i].p = DSTICKS[HOLES[i].Sticks[HOLES[i].d - 1]].p; else HOLES[i].p = 0; } return; } inline void Scoring() { SCOREC = KC * KC * KC; for(int i = 1; i <= KC; i++) { SCOREC += HOLES[i].p; } return; } inline void CheckC() { Scoring(); if(SCOREC < SCORE) { K = KC; SCORE = SCOREC; swap(HOLESFINAL, HOLES); } return; } inline void HoleClear() { int i = 1; while(HOLES[i].d) { HOLES[i].d = 0; HOLES[i].Sticks.clear(); HOLES[i].h = 0ll; HOLES[i].p = 0ll; i++; } return; } inline int StickBelowHeight(ll H, int L = 1, int R = N) { int RET = 0; int S; while(L <= R) { S = (L + R) >> 1; if(STICKS[S].h >= H) { R = S - 1; } else { RET = S; L = S + 1; } } return RET; } inline int StickAboveHeight(ll H, int L = 1, int R = N) { int RET = 0; int S; while(L <= R) { S = (L + R) >> 1; if(STICKS[S].h <= H) { L = S + 1; } else { RET = S; R = S - 1; } } return RET; } bool compStickPenalty(STICK e1, STICK e2) { if(e1.p > e2.p) return true; if(e1.p == e2.p) return e1.h < e2.h; return false; } bool compStickHeight(STICK e1, STICK e2) { if(e1.h < e2.h) return true; if(e1.h == e2.h) return e1.p > e2.p; return false; } bool compHoleHeight(HOLE e1, HOLE e2) { if(e1.h > e2.h) return true; if((e1.h == e2.h) && (e1.d < e2.d)) return true; return false; } bool compHolePenaltyRemove(int e1, int e2) { if(HOLES[e1].d < HOLES[e2].d) return true; if((HOLES[e1].d == HOLES[e2].d) && (HOLES[e1].p < HOLES[e2].p)) return true; return false; } inline void PenaltyRemoveHoles() { vector REMOVABLE; int E = 0; for(int i = 1; i <= KC; i++) { for(int j = 0; j < HOLES[i].d; j++) HOLES[i].p += DSTICKS[HOLES[i].Sticks[j]].p; REMOVABLE.push_back(i); if(HOLES[i].h < B) E++; } sort(REMOVABLE.begin(), REMOVABLE.end(), compHolePenaltyRemove); ll CKC = KC - 1; int k = KC - 1; for(int i = 0; i < KC; i++) { if(((CKC * CKC * CKC + HOLES[REMOVABLE[i]].p) < KC * KC * KC) && ((E - (HOLES[REMOVABLE[i]].h < B)) >= HOLES[REMOVABLE[i]].d)) { for(int j = HOLES[REMOVABLE[i]].d - 1; j >= 0; j--) { while(HOLES[REMOVABLE[k]].h >= B) k--; HOLES[REMOVABLE[k]].h += DSTICKS[HOLES[REMOVABLE[i]].Sticks[j]].h; HOLES[REMOVABLE[k]].d++; HOLES[REMOVABLE[k]].Sticks.push_back(HOLES[REMOVABLE[i]].Sticks[j]); LOCATIONS[HOLES[REMOVABLE[i]].Sticks[j]].k = REMOVABLE[k]; LOCATIONS[HOLES[REMOVABLE[i]].Sticks[j]].d = HOLES[REMOVABLE[k]].d - 1; } E -= HOLES[REMOVABLE[i]].d; HOLES[REMOVABLE[i]].h = 0ll; HOLES[REMOVABLE[i]].d = 0; HOLES[REMOVABLE[i]].Sticks.clear(); swap(HOLES[REMOVABLE[i]], HOLES[KC]); KC--; } } return; } inline void DisjointHolePenalty() { for(int i = 1; i <= KC; i++) { if(HOLES[i].h <= B) continue; for(int j = HOLES[i].d - 2; j >= 0; j--) { if(((HOLES[i].h - DSTICKS[HOLES[i].Sticks[j]].h) < B) && (DSTICKS[HOLES[i].Sticks[j]].p < DSTICKS[HOLES[i].Sticks[HOLES[i].d - 1]].p)) { swap(HOLES[i].Sticks[j], HOLES[i].Sticks[HOLES[i].d - 1]); swap(LOCATIONS[HOLES[i].Sticks[j]], LOCATIONS[HOLES[i].Sticks[HOLES[i].d - 1]]); } } } return; } inline void OverflowedHolePenalty() { if(N > 10000) return; STICK OverflowingStick; STICK SwappingStickC; STICK SwappingStick; queue OVERFLOWED; for(int i = 1; i <= KC; i++) if(HOLES[i].h > B) OVERFLOWED.push(i); int LIM = OVERFLOWED.size(); int i; for(int p = 1; p <= LIM; p++) { i = OVERFLOWED.front(); OVERFLOWED.pop(); OverflowingStick.h = DSTICKS[HOLES[i].Sticks[HOLES[i].d - 1]].h; if(OverflowingStick.h > B) continue; OverflowingStick.p = DSTICKS[HOLES[i].Sticks[HOLES[i].d - 1]].p; OverflowingStick.i = HOLES[i].Sticks[HOLES[i].d - 1]; SwappingStick = OverflowingStick; for(int j = 1; j <= N; j++) { if(LOCATIONS[STICKS[j].i].k == i) continue; if((HOLES[LOCATIONS[STICKS[j].i].k].h > B) && (LOCATIONS[STICKS[j].i].d == HOLES[LOCATIONS[STICKS[j].i].k].d - 1)) continue; SwappingStickC.h = DSTICKS[STICKS[j].i].h; if(SwappingStickC.h > B) continue; SwappingStickC.p = DSTICKS[STICKS[j].i].p; SwappingStickC.i = STICKS[j].i; if((SwappingStickC.p < SwappingStick.p) && ((HOLES[LOCATIONS[STICKS[j].i].k].h - DSTICKS[HOLES[LOCATIONS[STICKS[j].i].k].Sticks[HOLES[LOCATIONS[STICKS[j].i].k].d - 1]].h - SwappingStickC.h + OverflowingStick.h) < B)) { SwappingStick = SwappingStickC; } } if(SwappingStick.i == OverflowingStick.i) continue; HOLES[i].h += SwappingStick.h - OverflowingStick.h; HOLES[i].Sticks.pop_back(); HOLES[i].Sticks.push_back(SwappingStick.i); HOLES[LOCATIONS[SwappingStick.i].k].h += OverflowingStick.h - SwappingStick.h; remove(HOLES[LOCATIONS[SwappingStick.i].k].Sticks.begin(), HOLES[LOCATIONS[SwappingStick.i].k].Sticks.end(), SwappingStick.i); HOLES[LOCATIONS[SwappingStick.i].k].Sticks.pop_back(); HOLES[LOCATIONS[SwappingStick.i].k].Sticks.push_back(OverflowingStick.i); if(HOLES[LOCATIONS[SwappingStick.i].k].h > B) swap(HOLES[LOCATIONS[SwappingStick.i].k].Sticks[HOLES[LOCATIONS[SwappingStick.i].k].d - 1], HOLES[LOCATIONS[SwappingStick.i].k].Sticks[HOLES[LOCATIONS[SwappingStick.i].k].d - 2]); swap(LOCATIONS[OverflowingStick.i], LOCATIONS[SwappingStick.i]); } return; } inline void PenaltyAddHoles() { CalculateHolePenalty(); multimap MAP; multimap ::iterator it; multimap HOLEMAP; multimap ::iterator Hit; ll CKC = KC + 1ll; for(int i = 1; i <= KC; i++) if((HOLES[i].h > B) && (HOLES[i].d > 1)) MAP.insert(pair (-HOLES[i].p, i)); if(N <= 100000) for(int i = 1; i <= KC; i++) if(HOLES[i].h < B) HOLEMAP.insert(pair (B - HOLES[i].h, i)); STICK CurrentStick; for(it = MAP.begin(); it != MAP.end(); it++) { CurrentStick.h = DSTICKS[HOLES[it->second].Sticks.back()].h; if(CurrentStick.h > B) continue; CurrentStick.p = -it->first; CurrentStick.i = HOLES[it->second].Sticks.back(); Hit = HOLEMAP.lower_bound(CurrentStick.h); if(Hit != HOLEMAP.end()) { HOLES[it->second].h -= CurrentStick.h; HOLES[it->second].d--; HOLES[it->second].Sticks.pop_back(); HOLEMAP.insert(pair (B - HOLES[it->second].h, it->second)); HOLES[Hit->second].h += CurrentStick.h; HOLES[Hit->second].d++; HOLES[Hit->second].Sticks.push_back(CurrentStick.i); HOLEMAP.insert(pair (B - HOLES[Hit->second].h, Hit->second)); HOLEMAP.erase(Hit); continue; } if((CKC * CKC * CKC) < (KC * KC * KC + CurrentStick.p)) { KC++; CKC++; HOLES[it->second].h -= CurrentStick.h; HOLES[it->second].d--; HOLES[it->second].Sticks.pop_back(); HOLES[KC].h += CurrentStick.h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(CurrentStick.i); HOLEMAP.insert(pair (B - HOLES[KC].h, KC)); } } return; } inline void PenaltyFix() { DisjointHolePenalty(); OverflowedHolePenalty(); PenaltyAddHoles(); return; } inline void MapNoPenalty() { if(N > 100000) return; multimap MAP; multimap ::iterator it; KC = 1; for(int i = 1; i <= N; i++) MAP.insert(pair (STICKS[i].h, STICKS[i].i)); while(MAP.size()) { it = MAP.upper_bound(B - HOLES[KC].h); if(it != MAP.begin()) it--; if(it->first > (B - HOLES[KC].h)) { it = MAP.end(); it--; if(it->first <= B) { KC++; continue; } } HOLES[KC].h += it->first; HOLES[KC].d++; HOLES[KC].Sticks.push_back(it->second); LOCATIONS[it->second].k = KC; LOCATIONS[it->second].d = HOLES[KC].d - 1; MAP.erase(it); KC += HOLES[KC].h >= B; } while(!HOLES[KC].d) KC--; PenaltyRemoveHoles(); CalculateHolePenalty(); CheckC(); printf("MapNoPenalty:\t\t%lld;\tK: %lld;\n", SCOREC, KC); HoleClear(); return; } inline bool BinaryOK(int KC) { ll SUM, MAX; for(int i = KC; i >= 1; i--) { SUM = 0ll; MAX = 0ll; for(int j = i; j <= N; j += KC) { MAX = max(STICKS[j].h, MAX); SUM += STICKS[j].h; if((SUM - MAX) >= B) return false; } } return true; } inline void Binary() { reverse(STICKS + (N >> 1) + 1, STICKS + N + 1); int L = 1; int R = N; int S; while(L <= R) { S = (L + R) >> 1; if(!BinaryOK(S)) { L = S + 1; } else { KC = S; R = S - 1; } } for(int i = 1; i <= KC; i++) { for(int j = i; j <= N; j += KC) { HOLES[i].h += STICKS[j].h; HOLES[i].d++; HOLES[i].Sticks.push_back(STICKS[j].i); LOCATIONS[STICKS[j].i].k = i; LOCATIONS[STICKS[j].i].d = HOLES[i].d - 1; if((HOLES[i].d > 1) && (DSTICKS[HOLES[i].Sticks[HOLES[i].d - 1]].h < DSTICKS[HOLES[i].Sticks[HOLES[i].d - 2]].h)) { swap(HOLES[i].Sticks[HOLES[i].d - 1], HOLES[i].Sticks[HOLES[i].d - 2]); swap(LOCATIONS[HOLES[i].Sticks[HOLES[i].d - 1]], LOCATIONS[HOLES[i].Sticks[HOLES[i].d - 2]]); } } } while(!HOLES[KC].d) KC--; PenaltyFix(); CalculateHolePenalty(); CheckC(); printf("Binary:\t\t%lld;\tK: %lld;\n", SCOREC, KC); HoleClear(); reverse(STICKS + (N >> 1) + 1, STICKS + N + 1); return; } inline void LimitedMap(ll CKC) { int LIM = N - CKC; multimap MAP; multimap ::iterator it; for(int i = 1; i <= LIM; i++) MAP.insert(pair (STICKS[i].h, STICKS[i].i)); KC = 1ll; while(MAP.size()) { it = MAP.lower_bound(B - HOLES[KC].h); if(it == MAP.begin()) { if((it->first >= B) || (MAP.size() == 1)) it++; else { KC++; continue; } } it--; HOLES[KC].h += it->first; HOLES[KC].d++; HOLES[KC].Sticks.push_back(it->second); LOCATIONS[it->second].k = KC; LOCATIONS[it->second].d = HOLES[KC].d - 1; MAP.erase(it); KC += (HOLES[KC].h >= B); } while(!HOLES[KC].h) KC--; if(KC > CKC) { HoleClear(); return; } CKC = KC; KC = 1ll; int L = N + 1; int R = N; for(int i = LIM + 1; i <= N; i++) { while(HOLES[KC].h >= B) KC++; if(KC >= CKC) { L = i; break; } HOLES[KC].h += STICKS[i].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[i].i); LOCATIONS[STICKS[i].i].k = KC; LOCATIONS[STICKS[i].i].d = HOLES[KC].d - 1; } while(L <= R) { if(((HOLES[KC].h + STICKS[L].h) >= B) && HOLES[KC].h) { HOLES[KC].h += STICKS[R].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[R].i); LOCATIONS[STICKS[R].i].k = KC; LOCATIONS[STICKS[R].i].d = HOLES[KC].d - 1; R--; } else { HOLES[KC].h += STICKS[L].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[L].i); LOCATIONS[STICKS[L].i].k = KC; LOCATIONS[STICKS[L].i].d = HOLES[KC].d - 1; L++; } KC += HOLES[KC].h >= B; } KC = max(KC, CKC); while(!HOLES[KC].d) KC--; PenaltyFix(); CalculateHolePenalty(); CheckC(); HoleClear(); return; } inline bool MapBinaryOK(int KC) { int LIM = N - KC; if(STICKS[LIM].h >= B) return false; multimap MAP; multimap ::iterator it; for(int i = 1; i <= LIM; i++) MAP.insert(pair (STICKS[i].h, STICKS[i].i)); int CKC = 1; while(MAP.size()) { it = MAP.lower_bound(B - HOLES[CKC].h); if(it == MAP.begin()) { CKC++; continue; } it--; HOLES[CKC].h += it->first; MAP.erase(it); } for(int i = 1; i <= CKC; i++) HOLES[i].h = 0ll; return (CKC <= KC); } inline void MapBinary() { int L = 1; int R = N; int S; while((L <= R) && (clock() < END)) { S = (L + R) >> 1; if(N <= 100000) LimitedMap(S); if(!MapBinaryOK(S)) { L = S + 1; } else { KC = S; R = S - 1; } } int CKC = KC; int LIM = N - KC; multimap MAP; multimap ::iterator it; for(int i = 1; i <= LIM; i++) MAP.insert(pair (STICKS[i].h, STICKS[i].i)); KC = 1; while(MAP.size()) { it = MAP.lower_bound(B - HOLES[KC].h); if(it == MAP.begin()) { KC++; continue; } it--; HOLES[KC].h += it->first; HOLES[KC].d++; HOLES[KC].Sticks.push_back(it->second); LOCATIONS[it->second].k = KC; LOCATIONS[it->second].d = HOLES[KC].d - 1; MAP.erase(it); } KC = 1; L = N + 1; R = N; for(int i = LIM + 1; i <= N; i++) { HOLES[KC].h += STICKS[i].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[i].i); LOCATIONS[STICKS[i].i].k = KC; LOCATIONS[STICKS[i].i].d = HOLES[KC].d - 1; KC += HOLES[KC].h >= B; if(KC >= CKC) { L = i + 1; R = N; break; } } while(L <= R) { if(((HOLES[KC].h + STICKS[L].h) >= B) && HOLES[KC].h) { HOLES[KC].h += STICKS[R].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[R].i); LOCATIONS[STICKS[R].i].k = KC; LOCATIONS[STICKS[R].i].d = HOLES[KC].d - 1; R--; } else { HOLES[KC].h += STICKS[L].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[L].i); LOCATIONS[STICKS[L].i].k = KC; LOCATIONS[STICKS[L].i].d = HOLES[KC].d - 1; L++; } KC += HOLES[KC].h >= B; } while(!HOLES[KC].d) KC--; PenaltyFix(); CalculateHolePenalty(); CheckC(); printf("MBinary:\t\t%lld;\tK: %lld;\n", SCOREC, KC); HoleClear(); return; } inline void Fitting() { KC = 1; for(int i = 1; i <= N; i++) { if(HOLES[KC].h >= B) KC++; HOLES[KC].h += STICKS[i].h; HOLES[KC].Sticks.push_back(STICKS[i].i); HOLES[KC].d++; LOCATIONS[STICKS[i].i].k = KC; LOCATIONS[STICKS[i].i].d = HOLES[KC].d - 1; } while(!HOLES[KC].d) KC--; PenaltyFix(); CheckC(); printf("Fitting:\t\t%lld;\tK: %lld;\n", SCOREC, KC); HoleClear(); return; } inline void DoubleEndedFitting() { KC = 1; int L = 1; int R = N; while(L <= R) { if(((HOLES[KC].h + STICKS[L].h) >= B) && HOLES[KC].h) { HOLES[KC].h += STICKS[R].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[R].i); LOCATIONS[STICKS[R].i].k = KC; LOCATIONS[STICKS[R].i].d = HOLES[KC].d - 1; R--; } else { HOLES[KC].h += STICKS[L].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[L].i); LOCATIONS[STICKS[L].i].k = KC; LOCATIONS[STICKS[L].i].d = HOLES[KC].d - 1; L++; } KC += HOLES[KC].h >= B; } while(!HOLES[KC].h) KC--; PenaltyFix(); CalculateHolePenalty(); CheckC(); printf("DEF:\t\t%lld;\tK: %lld;\n", SCOREC, KC); HoleClear(); return; } inline void SquaredTopFitting() { if(N > 10000) return; KC = 1; int E = 0; bool FOUND; for(int i = 1; i <= N; i++) { if(((HOLES[KC].h + STICKS[i].h) >= B) && HOLES[KC].h) { FOUND = false; for(int j = StickBelowHeight(B - HOLES[KC].h, 1, i - 1); j >= 1; j--) { if((LOCATIONS[STICKS[j].i].k != KC) && ((HOLES[LOCATIONS[STICKS[j].i].k].h + STICKS[i].h - STICKS[j].h) < B)) { HOLES[KC].h += STICKS[j].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[j].i); HOLES[LOCATIONS[STICKS[j].i].k].h += STICKS[i].h - STICKS[j].h; HOLES[LOCATIONS[STICKS[j].i].k].Sticks.push_back(STICKS[i].i); LOCATIONS[STICKS[i].i].k = LOCATIONS[STICKS[j].i].k; LOCATIONS[STICKS[i].i].d = LOCATIONS[STICKS[j].i].d; swap(HOLES[LOCATIONS[STICKS[j].i].k].Sticks[LOCATIONS[STICKS[j].i].d], HOLES[LOCATIONS[STICKS[j].i].k].Sticks[HOLES[LOCATIONS[STICKS[j].i].k].d]); HOLES[LOCATIONS[STICKS[j].i].k].Sticks.pop_back(); LOCATIONS[STICKS[j].i].k = KC; LOCATIONS[STICKS[j].i].d = HOLES[KC].d - 1; FOUND = true; break; } } if(!FOUND) { E += HOLES[KC].h < B; KC++; } else continue; } if(E >= (N - i + 1)) { int k = 1; for(int j = i; j <= N; j++) { while(HOLES[k].h >= B) k++; HOLES[k].h += STICKS[j].h; HOLES[k].d++; HOLES[k].Sticks.push_back(STICKS[j].i); LOCATIONS[STICKS[j].i].k = k; LOCATIONS[STICKS[j].i].d = HOLES[k].d - 1; } break; } else { HOLES[KC].h += STICKS[i].h; HOLES[KC].d++; HOLES[KC].Sticks.push_back(STICKS[i].i); LOCATIONS[STICKS[i].i].k = KC; LOCATIONS[STICKS[i].i].d = HOLES[KC].d - 1; } } while(!HOLES[KC].d) KC--; PenaltyFix(); CalculateHolePenalty(); CheckC(); printf("STF:\t\t%lld;\tK: %lld;\n", SCOREC, KC); HoleClear(); return; } inline void MapFitting() { multimap MAP; multimap ::iterator it; KC = 1; for(int i = 1; i <= N; i++) MAP.insert(pair (STICKS[i].h, STICKS[i].i)); while(MAP.size()) { if(!HOLES[KC].d) it = MAP.begin(); else { it = MAP.lower_bound(B - HOLES[KC].h); if(it == MAP.begin()) it = MAP.end(); it--; } HOLES[KC].h += it->first; HOLES[KC].d++; HOLES[KC].Sticks.push_back(it->second); LOCATIONS[it->second].k = KC; LOCATIONS[it->second].d = HOLES[KC].d - 1; MAP.erase(it); KC += HOLES[KC].h > B; } while(!HOLES[KC].d) KC--; PenaltyFix(); CalculateHolePenalty(); CheckC(); printf("MapFitting:\t\t%lld;\tK: %lld;\n", SCOREC, KC); HoleClear(); return; } inline void HeightMapping() { if(N > 1000) return; int LIM = (N >> 1) + 1; for(int i = 1; i <= LIM; i++) { LimitedMap(i); } } inline void PenaltyMapping() { if(N > 1000) return; sort(STICKS + 1, STICKS + N + 1, compStickPenalty); int LIM = (N >> 1) + 1; for(int i = 1; i <= LIM; i++) { LimitedMap(i); } } inline void Input() { freopen("sticks.in", "r", stdin); scanf("%d %lld", &N, &B); for(int i = 1; i <= N; i++) { STICKS[i].i = i; } for(int i = 1; i <= N; i++) { scanf("%lld", &STICKS[i].h); } for(int i = 1; i <= N; i++) { scanf("%lld", &STICKS[i].p); } for(int i = 1; i <= N; i++) { DSTICKS[i].h = STICKS[i].h; DSTICKS[i].p = STICKS[i].p; } return; } inline void Output() { // sort(HOLESFINAL + 1, HOLESFINAL + K + 1, compHoleHeight); freopen("sticks.out", "w", stdout); printf("%lld\n", K); for(int i = 1; i <= K; i++) { printf("%d ", HOLESFINAL[i].d); for(int j = 0; j < HOLESFINAL[i].d; j++) { printf("%d ", HOLESFINAL[i].Sticks[j]); } printf("\n"); } return; } int main() { BEGIN = clock(); END = BEGIN + 3.2 * CLOCKS_PER_SEC; Input(); SetInitialScore(); sort(STICKS + 1, STICKS + N + 1, compStickHeight); MapNoPenalty(); MapFitting(); printf("Height "); SquaredTopFitting(); MapBinary(); HeightMapping(); PenaltyMapping(); printf("\n\nScore: %lld;\tK: %lld;\n\n", SCORE, K); Output(); return 0; } ///TO-DO: /// -Redom resi propuste u svakom algoritmu. /// -Napravi odrzavanje DSTICKS u svakom algoritmu. /// -Napravi najbolji algoritam za rasporedjivanje koji mozes, a posle toga mu napravi optimizaciju za Penalty. ***Trenutno ovo radim i ne mogu da razumem zasto ne mogu iterirati po rupama nakon sto sam proverio stap iz Bound-a. *** Ne mozes jer garancija da su svi manji ne vredi, posto si swappovo stapove... Idiote... /// -Napravi algoritam koji proverava da li je moguce skinuti neki penalty, po cenu nekoliko swappova ili po cenu nove rupe. /// -Napravi jednu jaku optimizaciju za NoPenalty algoritme /// -Napravi jednu jaku optimizaciju za trpanje algoritme. Sve stapove koji nisu na vrhovima rupa ubaci u mapu i onda pokusavaj za svaki stap da nadjes prvi sa najmanjim penaltijem koji odgovara?