Submission #312236

# Submission time Handle Problem Language Result Execution time Memory
312236 2020-10-12T20:36:06 Z aryan12 Gift (IZhO18_nicegift) C++17
0 / 100
33 ms 12780 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int f = 1, s = 2;
    vector<pair<int, pair<int, int> > >ans;
    while(f <= n && s <= n) {
        if(a[f] > a[s]) {
            a[f] -= a[s];
            ans.push_back({a[s], {f, s}});
            s = max(s, f) + 1;
        }
        else if(a[f] == a[s]) {
            ans.push_back({a[f], {f, s}});
            f = max(s, f) + 1;
            s = f + 1;
        }
        else {
            a[s] -= a[f];
            ans.push_back({a[f], {f, s}});
            f = max(s, f) + 1;
        }
    }
    if(f <= n || s <= n) {
        cout << "-1" << endl;
    }
    else {
        cout << ans.size() << endl;
        for(int i = 0; i < ans.size(); i++) {
            cout << ans[i].first << " " << ans[i].second.first << " " << ans[i].second.second << endl;
        }
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:35:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i = 0; i < ans.size(); i++) {
      |                        ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 256 KB n=3
3 Correct 1 ms 384 KB n=3
4 Incorrect 0 ms 384 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 256 KB n=3
3 Correct 1 ms 384 KB n=3
4 Incorrect 0 ms 384 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 256 KB n=3
3 Correct 1 ms 384 KB n=3
4 Incorrect 0 ms 384 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 12780 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 256 KB n=3
3 Correct 1 ms 384 KB n=3
4 Incorrect 0 ms 384 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -