CSES - Leirikisa 1 - Results
Submission details
Task:lopov
Sender:zxc
Submission time:2016-07-27 15:22:54 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.08 sdetails
#6ACCEPTED0.05 sdetails
#7ACCEPTED0.07 sdetails
#8ACCEPTED0.12 sdetails
#9ACCEPTED0.13 sdetails
#10ACCEPTED0.31 sdetails
#11ACCEPTED0.19 sdetails
#12ACCEPTED0.73 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:48:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i< pck.size(); ++i) {
                                ^

Code

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int MN = 3e5+100;
int m[MN];
int v[MN];
int c[MN];
const int N = 1<<19;
pair<int, int> st[2*N];
void setValue(int a, int v) {
    a += N;
    st[a].F = v;
    for(a/=2; a; a/=2) {
	st[a] = max(st[a*2], st[a*2+1]);
    }
}
int getMax(int a, int b) {
    a += N;
    b += N;
    pair<int, int> ma = {0, 0};
    for(; a <= b; a/=2, b/=2) {
	if(a&1) {
	    ma = max(ma, st[a++]);
	}
	if(~b&1) {
	    ma = max(ma, st[b--]);
	}
    }
    return ma.S;
}
vector<int> qwe[MN];
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> pck;
    for(int i = 0; i < n; ++i) {
	cin>>m[i]>>v[i];
	pck.push_back(m[i]);
    }
    for(int i = 0; i < k; ++i) {
	cin>>c[i];
	pck.push_back(c[i]);
    }
    sort(pck.begin(), pck.end());
    pck.erase(unique(pck.begin(), pck.end()), pck.end());
    map<int, int> mp;
    for(int i = 0; i< pck.size(); ++i) {
	mp[pck[i]] = i;
    }
    //cout<<"LOl\n";
    for(int i = 0; i < n; ++i) {
	m[i] = mp[m[i]];
//	cout<<m[i]<<' '<<v[i]<<'\n';
	qwe[m[i]].push_back(v[i]);
    }
 //   cout<<"lasfd\n";
    for(int i = 0; i < MN; ++i) {
	sort(qwe[i].begin(), qwe[i].end());
	st[i+N].S = i;
	if(qwe[i].size()) {
	    st[i+N] = {qwe[i].back(), i};
	    qwe[i].pop_back();
	}
    }
    for(int i = 0; i < k;++i) {
	c[i] = mp[c[i]];
    }
    sort(c, c+k);
    /*
    for(int i = 0; i < k; ++i) {
	cout<<c[i]<<' ';
    }
    cout<<'\n';
    cout<<"asdf\n";
    */
    for(int i = N-1; i; --i) {
	st[i] = max(st[i*2], st[i*2+1]);
    }
    long long ans = 0;
    for(int i = 0; i < k; ++i) {
	int q = getMax(0, c[i]);
//	cout<<c[i]<<' ';
	ans += st[N+q].F;
//	cout<<st[N+1].F<<'\n';
	if(st[N+q].F == 0) continue;
	if(qwe[q].size() == 0) {
	    setValue(q, 0);
	}
	else {
	    setValue(q, qwe[q].back());
	    qwe[q].pop_back();
	}
    }
    cout<<ans<<'\n';

}

Test details

Test 1

Verdict: ACCEPTED

input
2 1
5 10
100 100
11

correct output
10

user output
10

Test 2

Verdict: ACCEPTED

input
3 2
1 65
5 23
2 99
10
...

correct output
164

user output
164

Test 3

Verdict: ACCEPTED

input
10 10
1 1
6 5
8 12
10 20
...

correct output
285

user output
285

Test 4

Verdict: ACCEPTED

input
100 500
1 1
6 9
7 12
14 19
...

correct output
25259

user output
25259

Test 5

Verdict: ACCEPTED

input
1000 500
1 1
80 9
82 11
131 38
...

correct output
6230069

user output
6230069

Test 6

Verdict: ACCEPTED

input
1000 1010
1 1
5 4
10 9
11 13
...

correct output
638915

user output
638915

Test 7

Verdict: ACCEPTED

input
5000 1010
1 1
49 19
55 39
69 76
...

correct output
10595210

user output
10595210

Test 8

Verdict: ACCEPTED

input
50000 20000
96851 85347
94211 6050
64627 18074
9696 84124
...

correct output
1392413902

user output
1392413902

Test 9

Verdict: ACCEPTED

input
5000 100000
0 0
0 0
1 0
0 0
...

correct output
1695

user output
1695

Test 10

Verdict: ACCEPTED

input
100000 100000
132731 63644
182246 131322
184048 16187
60133 177080
...

correct output
10022686883

user output
10022686883

Test 11

Verdict: ACCEPTED

input
100000 100000
0 0
1 0
1 0
1 0
...

correct output
19941

user output
19941

Test 12

Verdict: ACCEPTED

input
300000 300000
912449 903033
992783 981923
959318 988091
934786 912569
...

correct output
285052149031

user output
285052149031