Submission #880393

# Submission time Handle Problem Language Result Execution time Memory
880393 2023-11-29T10:14:19 Z AlexMoysi Fountain (eJOI20_fountain) C++14
30 / 100
293 ms 5296 KB
#include <iostream>
#include <vector>
using namespace std;

struct Reservoir
{
    int diameter, volume, p_sum;
};

int bsearch(const vector<Reservoir>& Res, const int& R, int V)
{
    int start=R, m, end=Res.size() - 1, dif;
    
    if(R>0)
        dif = Res[R-1].p_sum;
    else
        dif = 0;    
    
    while(start <= end)
    {
        m = (start+end)/2;
        if(Res[m].p_sum - dif == V)
            return m + 1;
        
        else if(Res[m].p_sum - dif > V)
            end = m - 1;
        
        else
            start = m + 1;    
    }
    
    if(m < 0)
        return 1;
        
    else if(start<Res.size())
        return start + 1;
        
    return 0;  
}

int main()
{
    int N, Q;
    
    cin>>N>>Q;
    
    vector<Reservoir> Res;
    Res.resize(N);
    
    for(size_t c=0; c<N; c++)
        cin>>Res[c].diameter>>Res[c].volume;
    Res[0].p_sum = Res[0].volume; 
    for(size_t c=1; c<N; c++)
        Res[c].p_sum = Res[c-1].p_sum + Res[c].volume;      
        
    for(size_t c=0; c<Q; c++)
    {
        int R, V;
        cin>>R>>V;
        R--;
        
        cout<<bsearch(Res, R, V)<<endl;
    }    

    return 0;
}

Compilation message

fountain.cpp: In function 'int bsearch(const std::vector<Reservoir>&, const int&, int)':
fountain.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Reservoir>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     else if(start<Res.size())
      |             ~~~~~^~~~~~~~~~~
fountain.cpp: In function 'int main()':
fountain.cpp:50:22: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |     for(size_t c=0; c<N; c++)
      |                     ~^~
fountain.cpp:53:22: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |     for(size_t c=1; c<N; c++)
      |                     ~^~
fountain.cpp:56:22: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |     for(size_t c=0; c<Q; c++)
      |                     ~^~
fountain.cpp: In function 'int bsearch(const std::vector<Reservoir>&, const int&, int)':
fountain.cpp:32:5: warning: 'm' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     if(m < 0)
      |     ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 265 ms 5200 KB Output is correct
2 Correct 293 ms 5296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -