Problem p02658 (C++) — buggy submission, verdict: Runtime Error

/*
=================================
|                               |
|      WE ARE < YN > team       |
|                               |
|   learn more,more and more    |
|                               |
=================================
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define fastio                                                                 \\
  std::ios_base::sync_with_stdio(false), std::cout.tie(0), std::cin.tie(0);
#define N 1000000007
#define mxx INT_MAX
const double pi = 3.14159265359;

typedef long long ll;
// using namespace __gnu_pbds;
/*typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;*/

#define N 100007

void solve() {
  int num;
  std::cin >> num;
  ll arr[N]{};
  ll st = 1e18;
  ll sum = 1;
  for (int x = 0; x < num; x++)
    std::cin >> arr[x];
  std::sort(arr, arr + num);
  if (arr[0] == 0) {
    std::cout << 0;
    return;
  }
  for (int x = 0; x < num; x++) {

    if (arr[x] > st / sum) {
      std::cout << -1;
      return;
    }
    sum *= arr[x];
  }
  std::cout << sum;
}

int main() {
  int t;
  /*std::cin>>t;
  while(t--)*/
  solve();
}

/*void solve() {
        int n, m, q;
        std::cin >> n >> m >> q;
        std::string name1, name2;
        std::cin >> name1 >> name2;
        int s = name2.size();
        if (m > n) {
                for (int x = 0; x < q; x++) {
                        int num1, num2, count = 0;
                        std::cin >> num1 >> num2;
                        std::cout << 0 << "\\n";
                }
        }
        else {
                for (int x = 0; x < q; x++) {
                        int num1, num2, count = 0;
                        std::cin >> num1 >> num2;
                        for (int z = num1; z <= num2; z++) {
                                if (name1.substr(z, s) == name2)count++;
                        }std::cout << count << "\\n";
                }
        }
}
int main() {
        /*int t;
        std::cin >> t;
        while (t--)*
        solve();
}*/

/*void solve() {
        int arr1[100]{},arr2[100]{};
        int num,k;
        std::cin>>num>>k;
        for(int x=0;x<num;x++)std::cin>>arr1[x];
        for(int x=0;x<num;x++)std::cin>>arr2[x];

        std::sort(arr1,arr1+num);
        std::sort(arr2,arr2+num,std::greater<int>());
        for(int x=0;x<k;x++){
                if(arr2[x]>arr1[x]){
                        std::swap(arr1[x],arr2[x]);
                }else break;
        }
        int count=0;
        for(int x=0;x<num;x++){
                count+=arr1[x];
        }
        std::cout<<count<<"\\n";
}
int main() {
        int t;
        std::cin >> t;
        while (t--)
                solve();
}
*/

/*std::vector<int>arr;
int w;
int main() {
        //int arr[1000]{};
        int arr2[1000]{};
        int num,end;
        int count = 0, mx = 0;
        arr.push_back(0);
        std::cin >> num;
        for (int x = 1; x <= num; x++) {
                std::cin >>w, arr.push_back(w);
        }
        arr.push_back(0);
         //---------------------count subarray--------------------------//
        for (int x = 1; x <= num; x++) {
                if (arr2[arr[x]] == 0) {
                        arr2[arr[x]] = x;
                }
                else {
                        count = x - arr2[arr[x]]+1;
                        if (mx < count) {
                                end = x;
                                mx = std::max(mx, count);
                        }
                }

        }
        //std::cout << mx;
        //-------------------------find min
num----------------------------------// int X = end-mx+1; int XX = end; int mn =
999999999; for (int x = X+1; x <= XX-1 ; x++) { mn = std::min(mn, arr[x]);
        }

        std::cout << mx << " " << mn;
}

*/

/*int rem = v[0];
for (int z = 0; z < num; z++) {
        if (v[z] % rem == 0) {
                scan = 1;
        }
        else {
                scan = 0;
                z = 0;
                rem--;
        }

}*/

/*int main() {
        int n;
        std::cin>>n;
        while(n--) {
                int a,b,c,d;
                std::cin>>a>>b>>c>>d;
                int sum=a/b;
                int cant=(d/b)-((c-1)/b);
                std::cout<<sum-cant<<endl;
        }
}*/

/*int main(){
        int num;
        std::string name;
        std::cin>>num>>name;
        int count=0,top=0;
        for(int x=0;x<num;x++){
                if(name[x]=='U'){
                        top++;

                }else{
                        if(top==0)count++;
                        top--;
                }
        }
        if(top!=0)count--;
std::cout<<count;


}*/

Error: -11

Fixed submission:

/*
=================================
|                               |
|      WE ARE < YN > team       |
|                               |
|   learn more,more and more    |
|                               |
=================================
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define fastio                                                                 \\
  std::ios_base::sync_with_stdio(false), std::cout.tie(0), std::cin.tie(0);
#define N 1000000007
#define mxx INT_MAX
const double pi = 3.14159265359;

typedef long long ll;
// using namespace __gnu_pbds;
/*typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;*/

void solve() {
  int num;
  std::cin >> num;
  ll arr[N]{};
  ll st = 1e18;
  ll sum = 1;
  for (int x = 0; x < num; x++)
    std::cin >> arr[x];
  for (int x = 0; x < num; x++) {
    if (arr[x] == 0) {
      std::cout << 0;
      return;
    }
    if (arr[x] > st / sum) {
      std::cout << -1;
      return;
    }
    sum *= arr[x];
  }
  std::cout << sum;
}

int main() {
  int t;
  /*std::cin>>t;
  while(t--)*/
  solve();
}

/*void solve() {
        int n, m, q;
        std::cin >> n >> m >> q;
        std::string name1, name2;
        std::cin >> name1 >> name2;
        int s = name2.size();
        if (m > n) {
                for (int x = 0; x < q; x++) {
                        int num1, num2, count = 0;
                        std::cin >> num1 >> num2;
                        std::cout << 0 << "\\n";
                }
        }
        else {
                for (int x = 0; x < q; x++) {
                        int num1, num2, count = 0;
                        std::cin >> num1 >> num2;
                        for (int z = num1; z <= num2; z++) {
                                if (name1.substr(z, s) == name2)count++;
                        }std::cout << count << "\\n";
                }
        }
}
int main() {
        /*int t;
        std::cin >> t;
        while (t--)*
        solve();
}*/

/*void solve() {
        int arr1[100]{},arr2[100]{};
        int num,k;
        std::cin>>num>>k;
        for(int x=0;x<num;x++)std::cin>>arr1[x];
        for(int x=0;x<num;x++)std::cin>>arr2[x];

        std::sort(arr1,arr1+num);
        std::sort(arr2,arr2+num,std::greater<int>());
        for(int x=0;x<k;x++){
                if(arr2[x]>arr1[x]){
                        std::swap(arr1[x],arr2[x]);
                }else break;
        }
        int count=0;
        for(int x=0;x<num;x++){
                count+=arr1[x];
        }
        std::cout<<count<<"\\n";
}
int main() {
        int t;
        std::cin >> t;
        while (t--)
                solve();
}
*/

/*std::vector<int>arr;
int w;
int main() {
        //int arr[1000]{};
        int arr2[1000]{};
        int num,end;
        int count = 0, mx = 0;
        arr.push_back(0);
        std::cin >> num;
        for (int x = 1; x <= num; x++) {
                std::cin >>w, arr.push_back(w);
        }
        arr.push_back(0);
         //---------------------count subarray--------------------------//
        for (int x = 1; x <= num; x++) {
                if (arr2[arr[x]] == 0) {
                        arr2[arr[x]] = x;
                }
                else {
                        count = x - arr2[arr[x]]+1;
                        if (mx < count) {
                                end = x;
                                mx = std::max(mx, count);
                        }
                }

        }
        //std::cout << mx;
        //-------------------------find min
num----------------------------------// int X = end-mx+1; int XX = end; int mn =
999999999; for (int x = X+1; x <= XX-1 ; x++) { mn = std::min(mn, arr[x]);
        }

        std::cout << mx << " " << mn;
}

*/

/*int rem = v[0];
for (int z = 0; z < num; z++) {
        if (v[z] % rem == 0) {
                scan = 1;
        }
        else {
                scan = 0;
                z = 0;
                rem--;
        }

}*/

/*int main() {
        int n;
        std::cin>>n;
        while(n--) {
                int a,b,c,d;
                std::cin>>a>>b>>c>>d;
                int sum=a/b;
                int cant=(d/b)-((c-1)/b);
                std::cout<<sum-cant<<endl;
        }
}*/

/*int main(){
        int num;
        std::string name;
        std::cin>>num>>name;
        int count=0,top=0;
        for(int x=0;x<num;x++){
                if(name[x]=='U'){
                        top++;

                }else{
                        if(top==0)count++;
                        top--;
                }
        }
        if(top!=0)count--;
std::cout<<count;


}*/