Guest User

Untitled

a guest
Dec 3rd, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.59 KB | None | 0 0
  1. G = zeros(5000,60);
  2. x = sort(importdata('input.txt'));
  3. L = size(x,1);
  4. for i=1:L
  5.     idx = strfind(x{i},'#');
  6.     if idx
  7.         awake = true;
  8.         ID = sscanf(x{i}(idx+1:end),'%f');
  9.         continue
  10.     end
  11.     t = str2double(x{i}(16:17));
  12.     if awake
  13.         awake = false;
  14.         G(ID,t+1:end) = G(ID,t+1:end)+1;
  15.     else
  16.         awake = true;
  17.         G(ID,t+1:end) = G(ID,t+1:end)-1;
  18.     end
  19. end
  20. [a,b_idx] = max(sum(G,2));
  21. [c,c_idx] = max(G(b_idx,:));
  22. disp((c_idx-1)*b_idx) % Part 1
  23. [d,d_idx]=max(max(G,[],2));
  24. [e,e_idx] = max(G(d_idx,:));
  25. disp((e_idx-1)*d_idx) % Part 2
Advertisement
Add Comment
Please, Sign In to add comment