ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203760 | #534. 猫 | wosile | 100 | 1171ms | 3760kb | C++11 | 1.5kb | 2024-03-14 11:32:22 | 2024-03-14 21:22:30 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
int n,m,p;
int d[100005];
int a[50005];
ll f[50005][2];
int st[50005];
ll sum[50005];
ll X[50005],Y[50005];
bool checkconvex(int x,int y,int z){
// (Y[x]-Y[y])/(X[x]-X[y])>=(Y[y]-Y[z])/(X[y]-X[z])
return (Y[x]-Y[y])*(X[y]-X[z])>=(Y[y]-Y[z])*(X[x]-X[y]);
}
bool checkslope(int x,int y,int k){
// (Y[x]-Y[y])/(X[x]-X[y])<=k
// printf("%d %d %d\n",x,y,k);
// printf("%lld %lld %lld\n",Y[y]-Y[x],k,X[y]-X[x]);
return (Y[y]-Y[x])<=k*(X[y]-X[x]);
}
int main(){
scanf("%d%d%d",&n,&m,&p);
for(int i=2;i<=n;i++)scanf("%d",&d[i]);
for(int i=2;i<=n;i++)d[i]+=d[i-1];
for(int i=1;i<=m;i++){
int h,t;
scanf("%d%d",&h,&t);
a[i]=t-d[h];
}
sort(a+1,a+m+1);
// for(int i=1;i<=m;i++)printf("%d %d\n",1027,a[i]);
for(int i=1;i<=m;i++)sum[i]=sum[i-1]+a[i];
f[0][0]=0;
for(int i=1;i<=m;i++)f[i][0]=1e13;
for(int j=1;j<=p;j++){
for(int i=0;i<=m;i++){
X[i]=i;
Y[i]=f[i][1^(j&1)]+sum[i];
}
// printf("j=%d\n",j);
// if(j>=2)return 0;
int bk=1,top=0;
for(int i=1;i<=m;i++){
while(top>bk && checkconvex(st[top-1],st[top],i-1))--top;
st[++top]=i-1;
while(bk<top && checkslope(st[bk],st[bk+1],a[i]))++bk;
f[i][j&1]=f[st[bk]][1^(j&1)]+(ll)(i-st[bk])*a[i]-(sum[i]-sum[st[bk]]);
// printf("%d %d\n",bk,st[bk]);
// printf("f[%d][%d]=%lld\n",i,j,f[i][j&1]);
}
}
printf("%lld",f[m][p&1]);
return 0;
}
// quod erat demonstrandum
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 8ms
memory: 1556kb
input:
73571 1000 100 38 28 36 82 61 17 47 16 88 90 95 2 26 84 10 48 73 59 29 10 20 94 99 83 79 25 9 41 14 ...
output:
12590216
result:
ok single line: '12590216'
Test #2:
score: 10
Accepted
time: 6ms
memory: 1536kb
input:
67865 1000 100 30 94 97 56 41 18 12 96 27 29 94 76 36 45 75 34 67 98 97 18 86 97 36 76 24 46 34 5 33...
output:
11472767
result:
ok single line: '11472767'
Test #3:
score: 10
Accepted
time: 6ms
memory: 1632kb
input:
91328 1000 100 56 40 66 96 25 10 18 21 71 60 96 17 82 2 45 85 63 30 38 8 78 85 59 49 39 16 45 23 78 ...
output:
15417670
result:
ok single line: '15417670'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1316kb
input:
11409 1000 100 76 81 83 44 95 40 96 96 19 9 87 49 17 15 21 18 65 38 14 56 82 42 19 46 81 10 60 10 16...
output:
2054239
result:
ok single line: '2054239'
Test #5:
score: 10
Accepted
time: 75ms
memory: 1768kb
input:
79788 5000 1000 31 76 3 37 84 2 18 56 64 66 79 16 81 47 75 28 72 18 3 98 61 64 5 78 29 61 51 45 39 4...
output:
5137293
result:
ok single line: '5137293'
Test #6:
score: 10
Accepted
time: 70ms
memory: 1716kb
input:
65698 5000 1000 44 67 75 80 15 60 17 29 91 78 95 90 30 88 88 19 44 53 38 77 91 69 69 63 9 26 87 63 4...
output:
4283409
result:
ok single line: '4283409'
Test #7:
score: 10
Accepted
time: 71ms
memory: 1780kb
input:
81269 5000 1000 13 90 53 94 71 23 35 73 54 9 97 62 17 91 2 69 96 89 76 9 97 79 67 55 58 80 41 28 96 ...
output:
5295068
result:
ok single line: '5295068'
Test #8:
score: 10
Accepted
time: 66ms
memory: 1696kb
input:
61212 5000 1000 43 64 47 16 76 77 54 81 7 33 78 96 13 59 68 18 51 16 87 75 48 46 71 90 79 68 96 67 6...
output:
3944436
result:
ok single line: '3944436'
Test #9:
score: 10
Accepted
time: 779ms
memory: 3760kb
input:
92921 50000 1000 17 71 72 27 7 47 4 39 93 80 3 74 13 59 42 76 35 85 86 78 37 91 57 89 50 6 89 100 36...
output:
101887288
result:
ok single line: '101887288'
Test #10:
score: 10
Accepted
time: 90ms
memory: 3740kb
input:
93840 50000 100 96 92 90 98 100 94 99 94 96 93 96 93 96 91 100 90 99 100 91 99 93 97 98 100 95 95 91...
output:
2170029592
result:
ok single line: '2170029592'
Extra Test:
score: 0
Extra Test Passed