Submission #587549

# Submission time Handle Problem Language Result Execution time Memory
587549 2022-07-02T05:21:34 Z duyboy135 Distributing Candies (IOI21_candies) C++17
0 / 100
121 ms 14240 KB
#include "candies.h"

#include <bits/stdc++.h>

typedef std::pair<int, int> ii;

void push_to_stack(std::stack<int> &st, int toAdd){
    if(toAdd > 0){
        while(!st.empty() && st.top() + toAdd >= 0){
            toAdd += st.top();
            st.pop();
        }
        if(toAdd > 0)   st.push(toAdd);
    }
    else if(toAdd < 0){
        while(!st.empty() && st.top() + toAdd <= 0){
            toAdd += st.top();
            st.pop();
        }
        if(!st.empty() && toAdd < 0)    st.push(toAdd);
    }
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n);
    std::vector<ii> orders;
    std::stack<int> st;
    for(int i = 0; i < q; i++) push_to_stack(st, v[i]);
    for(int i = 0; i < n; i++)  orders.push_back(ii(c[i], i));
    sort(orders.begin(), orders.end());
    int cur = 0;
    for(auto it = orders.begin(); it != orders.end(); it++){
        while(!st.empty() && it->first >= abs(st.top())){
            cur += st.top();
            st.pop();
        }
        if(st.size()%2) s[it->second] = cur + it->first;
        else s[it->second] = cur;
    }
    return s;
}


//int main() {
//    freopen("test.inp","r",stdin);
//    int n;
//    assert(1 == scanf("%d", &n));
//    std::vector<int> c(n);
//    for(int i = 0; i < n; ++i) {
//        assert(scanf("%d", &c[i]) == 1);
//    }
//
//    int q;
//    assert(1 == scanf("%d", &q));
//    std::vector<int> l(q), r(q), v(q);
//    for(int i = 0; i < q; ++i) {
//        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
//    }
//
//    std::vector<int> ans = distribute_candies(c, l, r, v);
//
//    for(int i = 0; i < n; ++i) {
//        if (i > 0) {
//            printf(" ");
//        }
//        printf("%d", ans[i]);
//    }
//    printf("\n");
//    fclose(stdout);
//    return 0;
//}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 121 ms 9440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 56 ms 7636 KB Output is correct
4 Correct 66 ms 6080 KB Output is correct
5 Correct 109 ms 13004 KB Output is correct
6 Correct 118 ms 13632 KB Output is correct
7 Incorrect 114 ms 14240 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -