Programmers army monthly contest , REMIX problem

Can anyone tell me what mistake I’m making in this code?

#include<bits/stdc++.h>

using namespace std;

#define int long long

#define m 1000000007

#define pd push_back

#define f(a,b,c) for(int i=a;i<b;i+=c)

signed main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int t=1; while(t--)

{

    string s;

    getline(cin,s);

    string smal; 

    int si = INT_MAX;

    vector<string> v;

    string temp = "";

    for(int i=0;s[i];i++)

    {

        if(s[i]==' ')

        {

            v.pd(temp);

            if(si > temp.size())

            {smal = temp; si=temp.size();}

            temp = "";

        }

        else{

            temp+=s[i];

        }

    }

    if(si > temp.size())

    smal = temp;

    v.pd(temp); 

    for(auto val:v)

    {cout<<smal<<" ";

    cout<<val<<" ";}

    cout<<smal<<" ";

}

return 0;

}

I don’t find any mistake in your code. My code which used the same approach worked fine. And, it seems you are making it bit complex, or may be, I haven’t understood your approach correctly.

I have solved this problem with a different approach but curious to know what’s going wrong here.