Sequential vs Parallel Time (Simulation)
JavaScript
Medium
3 views
Problem Description
You have n task durations. If done sequentially, total is sum. If done in parallel with unlimited workers, total is max. Print both totals.
Input Format
Line1: n. Line2: n integers durations.
Output Format
Two integers: sequential parallel.
Official Solution
const fs=require('fs');const raw=fs.readFileSync(0,'utf8').trim();if(!raw)process.exit(0);const a=raw.split(/\\s+/).map(Number);let i=0;const n=a[i++];let sum=0;let mx=0;for(let j=0;j<n;j++){const d=a[i++];sum+=d;if(d>mx)mx=d;}const calc=async()=>{await Promise.resolve();return [sum,mx];};(async()=>{const [s,m]=await calc();process.stdout.write(s+' '+m);})();
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!