Submission #840103

# Submission time Handle Problem Language Result Execution time Memory
840103 2023-08-31T06:44:18 Z Faisal_Saqib A Plus B (IOI23_aplusb) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> smallest_sum(int n,vector<int> a,vector<int> b)
{
    vector<int> ans;
    int can[a.size()];
    int m=b.size();
    for(int i=0;i<n;i++)
    {
        can[i]=0;
    }
    set<pair<int,pair<int,int>>> pq;
    pq.insert({a[0]+b[0],{0,0}});
    while(ans.size()<(n) and pq.size()>0)
    {
        auto p=*begin(pq);
        pq.erase(begin(pq));
        ans.push_back(p.first);
        if(p.second.first< (n-1)){
            pq.insert({a[p.second.first+1]+b[can[p.second.first+1]],{p.second.first+1,can[p.second.first+1]}});
        }
        if(p.second.second< (m-1))
        {
            pq.insert({a[p.second.first]+b[p.second.second+1],{p.second.first,p.second.second+1}});
            can[p.second.first]+=1;
        }
    }
    for(auto i:ans)
    {
        cout<<i<<' ';
    }
    cout<<endl;
    return ans;
}
int main()
{
    int n;
    cin>>n;
    vector<int> a,b;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        a.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        b.push_back(x);
    }
    smallest_sum(n,a,b);
}

Compilation message

aplusb.cpp: In function 'std::vector<int> smallest_sum(int, std::vector<int>, std::vector<int>)':
aplusb.cpp:14:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   14 |     while(ans.size()<(n) and pq.size()>0)
      |           ~~~~~~~~~~^~~~
/usr/bin/ld: /tmp/ccAlqyA4.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc7zma67.o:aplusb.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccAlqyA4.o: in function `main':
grader.cpp:(.text.startup+0x271): undefined reference to `smallest_sums(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status