QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225810 | #1495. Lifeguards | paul2008 | 100 ✓ | 133ms | 154116kb | C++14 | 1.5kb | 2023-10-25 09:31:15 | 2023-10-25 09:31:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct node
{
int l,r;
};
const int N=1e5+5;
const int K=105;
node a[N];
bool cmp(node a,node b)
{
if(a.l!=b.l)
return a.l<b.l;
return a.r>b.r;
}
int dp[N][K],s[N][K];
deque <int> q[N];
inline int val(int i,int j)
{
return dp[i][i-j]-a[i].r;
}
int main()
{
int n,k;
cin >> n >> k;
for(int i=1;i<=n;i++)
scanf("%d %d",&a[i].l,&a[i].r);
sort(a+1,a+n+1,cmp);
int maxr=0,cnt=0;
for(int i=1;i<=n;i++)
if(a[i].r>maxr)
maxr=a[i].r, a[++cnt]=a[i];
k=max(0,cnt-(n-k)), n=cnt;
dp[1][0]=s[1][0]=a[1].r-a[1].l;
q[1].push_back(1);
for(int i=2;i<=n;i++)
{
int l=1,r=i-1,maxr=0;
while(l<=r)
{
int mid=(l+r)/2;
if(a[mid].r<=a[i].l)
maxr=mid,l=mid+1;
else
r=mid-1;
}
for(int j=0;j<=min(i-1,k);j++)
{
dp[i][j]=a[i].r-a[i].l;
if(maxr>=i-j-1)
dp[i][j]=s[maxr][maxr-(i-j-1)]+a[i].r-a[i].l;
while(q[i-j-1].size() && q[i-j-1].front()<=maxr)
q[i-j-1].pop_front();
if(q[i-j-1].size())
dp[i][j]=max(dp[i][j],val(q[i-j-1].front(),i-j-1)+a[i].r);
}
for(int j=0;j<=min(i-1,k);j++)
{
s[i][j]=dp[i][j];
if(j)
s[i][j]=max(s[i][j],s[i-1][j-1]);
while(q[i-j].size() && val(q[i-j].back(),i-j)<val(i,i-j))
q[i-j].pop_back();
q[i-j].push_back(i);
}
}
int ans=0;
for(int i=1;i<=n;i++)
for(int j=0;j<=min(i-1,k);j++)
if(j+n-i>=k)
ans=max(ans,dp[i][j]);
printf("%d\n",ans);
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 13ms
memory: 75616kb
input:
3 2 1 8 7 15 2 14
output:
12
result:
ok single line: '12'
Test #2:
score: 10
Accepted
time: 3ms
memory: 73976kb
input:
472 55 6077888 6090064 4871999 4878615 6946038 6955143 4328881 4337634 1931352 1940408 454117 462732 6296524 6307990 7212884 7222635 6199142 6211836 2544278 2551731 5138514 5144975 768019 777521 3349408 3360238 6502417 6515212 2671322 2679911 5679621 5689974 5064564 5076236 3342118 3352147 1387927 1...
output:
3700813
result:
ok single line: '3700813'
Test #3:
score: 10
Accepted
time: 16ms
memory: 79072kb
input:
4882 96 62535412 62542106 36668995 36676588 60378848 60389260 30255170 30265084 40053562 40062645 10822894 10831850 40682754 40691305 49193176 49200764 59666953 59677300 52101687 52111039 4752389 4760050 44845301 44852519 9975521 9983341 24546990 24552977 24390074 24399791 28729785 28735574 40731708...
output:
39948523
result:
ok single line: '39948523'
Test #4:
score: 10
Accepted
time: 74ms
memory: 116984kb
input:
50000 99 3443253 3444269 19799569 19800312 29048793 29049509 18895919 18896575 4162605 4163386 667095 668398 32700218 32701186 14340528 14341243 29758397 29759020 35017650 35018705 11398332 11399287 17166070 17166873 21725927 21726946 24253559 24254394 23711013 23711855 7156994 7158074 10624169 1062...
output:
37434346
result:
ok single line: '37434346'
Test #5:
score: 10
Accepted
time: 64ms
memory: 116632kb
input:
49785 82 27415369 27416397 21836194 21837490 26624191 26625262 36940507 36941408 19852564 19853310 31137285 31138343 22022992 22023887 50267822 50268790 34419182 34420086 231738 232630 11043268 11044061 41792530 41793349 39156666 39157524 45696387 45697645 57959783 57960633 68210455 68211426 4555506...
output:
41007479
result:
ok single line: '41007479'
Test #6:
score: 10
Accepted
time: 103ms
memory: 132804kb
input:
70000 98 4980448 4981537 45562845 45563749 4158845 4159702 43021974 43023083 21732970 21733657 48321143 48322537 7721899 7723060 14647548 14648843 20009619 20010569 48379190 48379880 9468982 9469778 37597526 37598243 43554589 43555522 8085136 8085922 13274471 13275640 40237288 40238250 38888652 3888...
output:
52435734
result:
ok single line: '52435734'
Test #7:
score: 10
Accepted
time: 133ms
memory: 154116kb
input:
100000 95 31394575 31395303 35035434 35036166 64896609 64897277 10992021 10992677 17899328 17900254 21235049 21236085 21825260 21826397 72355491 72356628 51097934 51098793 43022528 43023255 18626033 18626949 48380368 48381142 36901660 36902699 53823523 53824143 57181044 57181912 37079551 37080686 20...
output:
74878135
result:
ok single line: '74878135'
Test #8:
score: 10
Accepted
time: 110ms
memory: 154112kb
input:
100000 83 233039267 233039367 916657359 916657459 864715109 864715209 936842396 936842496 562959930 562960030 730029506 730029606 232012643 232012743 684125439 684125539 74354656 74354756 969280947 969281047 616579106 616579206 10886963 10887063 146442201 146442301 936755868 936755968 241861614 2418...
output:
9880370
result:
ok single line: '9880370'
Test #9:
score: 10
Accepted
time: 92ms
memory: 153840kb
input:
100000 90 816642137 816642237 185449925 185450025 619425312 619425412 335954840 335954940 14523568 14523668 522597020 522597120 755982712 755982812 749835334 749835434 16269569 16269669 577427902 577428002 378757393 378757493 290013689 290013789 299170714 299170814 598078466 598078566 85965624 85965...
output:
9879012
result:
ok single line: '9879012'
Test #10:
score: 10
Accepted
time: 104ms
memory: 154060kb
input:
100000 85 932471751 932471851 591128329 591128429 632579047 632579147 902529780 902529880 377540930 377541030 406044684 406044784 895898124 895898224 11965789 11965889 206361200 206361300 33540488 33540588 150614655 150614755 713801692 713801792 169829160 169829260 814073789 814073889 335070678 3350...
output:
9876663
result:
ok single line: '9876663'