-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrwccp6.cpp
More file actions
72 lines (66 loc) · 1.37 KB
/
strwccp6.cpp
File metadata and controls
72 lines (66 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
// #define int long long
#define mp(a,b) make_pair(a,b)
#define eb emplace_back
#define pb push_back
#define lsb(i) i & (-i + 1)
#define clear(array,fill) memset(array,fill,sizeof(array))
#ifdef fread_unlocked
#define fread fread_unlocked
#endif
#define PII pair<int, int>
using namespace std;
int n,maxd;
vector<PII>tasks;
bool ok(int mp){
int taskct=0;
int carryover=0;
for(int d=1;d<=maxd&&taskct<tasks.size();d++){
int ct=mp;
while(ct>0&&taskct<tasks.size()){
const auto[due,t]=tasks[taskct];
if(d>due){
// printf("Impossible to finish task: %d\n",due);
return false;
}
if(ct+carryover>=t){
// printf("Finish task: %d | %d\n",due,t);
ct-=((ct+carryover)-t);
taskct++;
carryover=0;
}else{
// printf("Work on task: %d %d\n",due,t);
carryover=ct+carryover;
ct=0;
}
}
}
return taskct==tasks.size();
}
signed main() {
#ifdef LOCAL
freopen("sample.in","r",stdin);
#endif
scanf("%d",&n);
for(int i=0;i<n;i++){
int t,d;scanf("%d %d",&t,&d);
maxd=max(maxd,d);
tasks.eb(mp(d,t));
}
sort(tasks.begin(),tasks.end());
int l=0,r=1441;
while(r>l){
int mp=(l+r)/2;
if(ok(mp)){
r=mp;
}else{
l=mp+1;
}
}
if(l==1441){
printf("gg go next");
return 0;
}
printf("%d",r);
return 0;
}