QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414749 | #6564. Frequent Flier | karuna# | RE | 62ms | 17252kb | C++20 | 1.1kb | 2024-05-19 16:27:09 | 2024-05-19 16:27:09 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 4e5;
int N, M, K, A[MAXN+10];
struct BIT
{
ll tree[MAXN+10];
void update(int i, ll k) { for(; i<=N; i+=(i&-i)) tree[i]+=k; }
ll query(int i) { ll ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }
ll query(int l, int r)
{
l=max(l, 1);
r=min(r, N);
return query(r)-query(l-1);
}
}bit;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
scanf("%d%d%d", &N, &M, &K);
for(int i=1; i<=N; i++) scanf("%d", &A[i]);
map<int, int> MM;
for(int i=1; i<=N; i++) MM[i]=A[i];
ll ans=0;
for(int i=1; i<=N+M-1; i++)
{
int t=K-bit.query(i-M+1, i);
for(auto it=prev(MM.upper_bound(i)); it->first>=i-M+1 && t;)
{
if(t>=it->second)
{
bit.update(it->first, it->second);
ans+=it->second;
t-=it->second;
it=MM.erase(it);
if(it==MM.begin()) break;
it--;
}
else
{
bit.update(it->first, t);
it->second-=t;
ans+=t;
break;
}
}
}
printf("%lld\n", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5784kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 62ms
memory: 17252kb
input:
200000 2467 999931035 182548858 69876218 33328350 919486767 739850600 948199964 392292320 39077742 366752074 917496841 246661698 37219034 56677740 188278971 965701828 28059790 13200243 825730775 542597589 320715170 939054378 470563899 914247467 990100491 290827128 903662394 611104879 18631185 412134...
output:
82994275905
result:
ok single line: '82994275905'
Test #3:
score: -100
Runtime Error
input:
1 200000 999959273 1255319