Submission #466683

# Submission time Handle Problem Language Result Execution time Memory
466683 2021-08-20T07:17:43 Z JvThunder Distributing Candies (IOI21_candies) C++17
0 / 100
486 ms 18244 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int MAXQ = 1000005;
const ll INF = (ll)(1e18);

vector<int> distribute_candies(vector<int> c, vector<int> L, vector<int> R, vector<int> v) 
{
    int n = c.size(); int q = v.size();
    
    vector<ll> p;
    p.push_back(INF); p.push_back(0LL);
    for(int i=0;i<q;i++) p.push_back(p.back()+v[i]);
    q+=2;

    vector<ll> smax(q),smin(q);
    smax[q-1] = smin[q-1] = p[q-1];
    for(int i=q-2;i>=0;i--)
    {
        smax[i] = max(smax[i+1],p[i]);
        smin[i] = min(smin[i+1],p[i]);
    }

    vector<int> final_A(n);
    for(int i=0;i<n;i++)
    {
        int l = 0; int r = q-1;
        int ret = -1;
        while(l<=r)
        {
            int mid = (l+r)/2;
            if(smax[mid]-smin[mid]<c[i]) r = mid-1;
            else ret = mid, l = mid+1;
        }
        cout << ret << endl;
        if(p[ret]==smax[ret]) final_A[i] = 0+(p[q-1]-smin[ret]);
        if(p[ret]==smin[ret]) final_A[i] = c[i]-(smax[ret]-p[q-1]);
    }
    return final_A;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 486 ms 18244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -