Submission #894841

# Submission time Handle Problem Language Result Execution time Memory
894841 2023-12-29T05:45:10 Z Muhammad_Aneeq Distributing Candies (IOI21_candies) C++17
0 / 100
5000 ms 9300 KB
#include <vector>
using namespace std;
int const N=2e5+10;
int n;
vector<int> distribute_candies(vector<int> c, vector<int> l,vector<int> r, vector<int> v)
{
    n=c.size();
    bool w=0;
    for (auto i:v)
        if (i<0)
            w=1;
    if (w==0)
    {
        vector<long long>d(n+1,0);
        for (int i=0;i<l.size();i++)
        {
            d[l[i]]+=v[i];
            d[r[i]+1]-=v[i];
        }
        vector<int>ans;
        ans.push_back(d[0]);
        for (int i=1;i<n;i++)
            ans.push_back(d[i]-ans.back());
        for (int i=0;i<n;i++)
        {
            ans[i]=(ans[i]<0?0:ans[i]);
            ans[i]=min(c[i],ans[i]);
        }
        return ans;
    }
    vector<int>ans(n,0);
    for (int i=0;i<l.size();i++)
    {
        for (int j=l[i];j<=r[i];j++)
        {
            ans[j]+=v[i];
            ans[j]=min(ans[j],c[j]);
            ans[j]=(ans[j]<0?0:ans[j]);
        }
    }
    return ans;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for (int i=0;i<l.size();i++)
      |                      ~^~~~~~~~~
candies.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i=0;i<l.size();i++)
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 9300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 170 ms 5096 KB Output is correct
3 Correct 168 ms 3820 KB Output is correct
4 Execution timed out 5012 ms 7388 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 431 ms 5100 KB Output is correct
4 Correct 407 ms 2816 KB Output is correct
5 Execution timed out 5027 ms 7392 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -