# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
800168 | Khizri | Distributing Candies (IOI21_candies) | C++17 | 65 ms | 18164 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2005;
int n,q;
vector<ll>pre[mxn];
vector<int> distribute_candies(vector<int> c, vector<int> x, vector<int> y, vector<int> vq) {
n = c.size();
q=x.size();
for(int i=0;i<q;i++){
int l=x[i],r=y[i],val=vq[i];
for(int j=l;j<=r;j++){
pre[j].pb(vq[i]);
}
}
vector<int>ans;
for(int id=0;id<n;id++){
int lim=c[id];
for(int i=1;i<pre[id].size();i++){
pre[id][i]+=pre[id][i-1];
}
ll mx=-INF,mn=INF,idx=-1,idx2=-1;
for(int i=0;i<pre[id].size();i++){
if(pre[id][i]>=mx){
mx=pre[id][i];
idx=i;
}
}
for(int i=idx+1;i<pre[id].size();i++){
if(pre[id][i]<=mn){
mn=pre[id][i];
idx2=i;
}
}
cout<<mn<<' '<<mx<<endl;
if(pre[id].size()==0){
ans.pb(0);
}
else if(mx<=lim&&mx>=0&&mn>=0&&mn<=lim){
ans.pb(pre[id].back());
}
else{
if(idx2>idx&&mx-mn>lim){
ans.pb(min(1ll*lim,pre[id].back()-pre[id][idx2]));
}
else{
ans.pb(max(0ll,abs(pre[id].back()-(pre[id][idx]-lim))));
}
}
}
return ans;
}
/*
g++ candies.cpp grader.cpp ; .\a.exe
3
10 15 13
2
0 2 20
0 1 -11
1
4
9
0 0 -100
0 0 4
0 0 -8
0 0 200
0 0 -5
0 0 2
0 0 1
0 0 -2
0 0 1
1
4
3
0 0 -60
0 0 -41
0 0 100
-100 -96 -104 96 91 93 94 92 93
1
10
6
0 0 -100
0 0 5
0 0 7
0 0 -4
0 0 2
0 0 1
-100 -95 -88 -92 -90 -89
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |