QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100526 | #3998. The Profiteer | 1kri | WA | 1ms | 5500kb | C++14 | 2.1kb | 2023-04-26 17:30:24 | 2023-04-26 17:30:26 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
int read(){
int x=0;
char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x;
}
int n,k,E,v[200005],a[200005],b[200005];
namespace QwQ{
int p;
ll f[20000005];
void ins(int t,int v){
p+=k;
for (int i=0;i<=k;i++){
f[p+i]=f[p+i-k];
if (i>=t)f[p+i]=max(f[p+i],f[p+i-t]+v);
}
return;
}
ll ask(){
ll sum=0;
for (int i=1;i<=k;i++)sum+=f[p+i];
return sum;
}
}
int ans[200005];
ll sum;
int find(int lt,int rt){
int l=lt,r=rt-1,ans=rt;
int p=QwQ::p;
if (rt!=n+1)QwQ::ins(a[rt],v[rt]);
while(l<=r){
int mid=(l+r)/2;
int p=QwQ::p;
for (int i=l;i<=mid;i++)QwQ::ins(b[i],v[i]);
for (int i=mid+1;i<=r;i++)QwQ::ins(a[i],v[i]);
if (QwQ::ask()<=1ll*k*E){
ans=mid;
QwQ::p=p;
for (int i=mid;i<=r;i++)QwQ::ins(a[i],v[i]);
r=mid-1;
}
else{
QwQ::p=p;
for (int i=l;i<=mid;i++)QwQ::ins(b[i],v[i]);
l=mid+1;
}
}
QwQ::p=p;
return ans;
}
void work(int l1,int r1,int l2,int r2){
if (l1>r1)return;
// QwQ::p=0;
// for (int i=1;i<=n;i++){
// if (i<l1)QwQ::ins(a[i],v[i]);
// if (i>r1&&i<l2)QwQ::ins(b[i],v[i]);
// if (i>r2)QwQ::ins(a[i],v[i]);
// }
int p=QwQ::p;
int mid=(l1+r1)/2;
for (int i=l1;i<mid;i++)QwQ::ins(a[i],v[i]);
for (int i=mid;i<=r1&&i<l2;i++)QwQ::ins(b[i],v[i]);
int q=find(max(mid,l2),r2);
ans[mid]=q;
int _p=QwQ::p;
for (int i=q+1;i<=r2;i++)QwQ::ins(a[i],v[i]);
for (int i=mid;i<=r1;i++)
if (i<l2)QwQ::ins(b[i],v[i]);
work(l1,mid-1,l2,q);
QwQ::p=_p;
for (int i=l1;i<=mid;i++)QwQ::ins(a[i],v[i]);
for (int i=l2;i<=q-1;i++)
if (i>r1)QwQ::ins(b[i],v[i]);
work(mid+1,r1,q,r2);
QwQ::p=p;
return;
}
int main(){
n=read(),k=read(),E=read();
for (int i=1;i<=n;i++)v[i]=read(),a[i]=read(),b[i]=read();
for (int i=1;i<=n;i++)QwQ::ins(a[i],v[i]);
if (QwQ::ask()<=1ll*k*E){
cout<<1ll*n*(n+1)/2<<endl;
return 0;
}
QwQ::p=0;
work(1,n,1,n+1);
for (int i=1;i<=n;i++)sum+=(n+1-ans[i]);
cout<<sum<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5500kb
input:
4 5 3 3 2 4 1 2 3 2 1 2 3 1 3
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'