题解
反悔贪心,或者说是贪心+优先队列。
code
class Solution { public: static bool cmp(vector<int > a,vector<int > b){ if (a[1]!=b[1]) return a[1]<b[1]; return a[0]<b[0]; } int scheduleCourse(vector<vector<int>>& courses) { int cnt=courses.size(); sort(courses.begin(),courses.end(),cmp); int ans=0,now=0; priority_queue<int > que; for (int i=0;i<cnt;i++){ if (now+courses[i][0]<=courses[i][1]){ now+=courses[i][0]; que.push(courses[i][0]); } else if (!que.empty()){ int x=que.top(); if (courses[i][0]<=x){ que.pop(); now+=courses[i][0]-x; que.push(courses[i][0]); } } } return que.size(); } };
标签:630,int,力扣,courses,课程表,iii From: https://www.cnblogs.com/purple123/p/18592500