Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var elevator = {
- mp: 0,
- mw: 0,
- pc: 0,
- w: 0,
- sc: 0,
- fc: 0,
- fl: [],
- push: function(person) {
- if (this.w + person.weight <= this.mw && this.pc +1 <= this.mp) {
- this.w += person.weight;
- this.pc += 1;
- if (this.fl.indexOf(person.floor) === -1) {
- this.fl.push(person.floor);
- }
- return true;
- }
- return false;
- },
- clear: function() {
- this.fc += (this.fl.length + 1);
- this.pc = 0;
- this.w = 0;
- this.fl = [];
- },
- init: function(mp, mw) {
- this.mw = mw;
- this.mp = mp;
- }
- }
- function solution(A, B, M, X, Y) {
- elevator.init(X, Y);
- var people = A.map(function(c, i) {
- return {weight: c, floor:B[i]};
- });
- while (people.length >0) {
- while (people.length >0 && elevator.push(people[0])) {
- people.shift();
- }
- elevator.clear();
- }
- return elevator.fc;
- }
- var A = [60, 80, 40];
- var B = [2, 3, 5];
- var M = 5;
- var X = 2;
- var Y = 200;
- var x = solution(A, B, M, X, Y);
- console.log(x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement