Codeforces Round #307 (Div. 2)

A. GukiZ and Contest
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.

In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.

He thinks that each student will take place equal to Codeforces Round #307 (Div. 2). In particular, if student A has rating strictly lower then student BA will get the strictly better position than B, and if two students have equal ratings, they will share the same position.

GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.

Input

The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students.

The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n).

Output

In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input.

Examples
input
3
1 3 3
output
3 1 1
input
1
1
output
1
input
5
3 5 3 4 5
output
4 1 4 3 1
Note

In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.

In the second sample, first student is the only one on the contest.

In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3are the last sharing fourth position.

 问你一个数排第几

#include<bits/stdc++.h>
using namespace std;
int a[2005];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int s=1;
    for(int j=0;j<n;j++)
        if(a[j]>a[0])s++;
    printf("%d",s);
    for(int i=1;i<n;i++){
        s=1;
        for(int j=0;j<n;j++)
        if(a[j]>a[i])s++;
    printf(" %d",s);}
    return 0;
}

直接这样枚举也能过,所以,sort的也能过吧

#include<bits/stdc++.h>
using namespace std;
int a[2005],b[2005];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    copy(a,a+n,b);
    sort(b,b+n);
    cout<<n-(upper_bound(b,b+n,a[0])-b)+1;
    for(int i=1;i<n;i++)
        cout<<" "<<n-(upper_bound(b,b+n,a[i])-b)+1;
    return 0;
}

完美,直接upper_bound美滋滋

B. ZgukistringZ
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.

GukiZ has strings ab, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x is a string formed by consecutive segment of characters from x. Two substrings of string x overlap if there is position i in string x occupied by both of them.

GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings k?

Input

The first line contains string a, the second line contains string b, and the third line contains string c (1 ≤ |a|, |b|, |c| ≤ 105, where |s| denotes the length of string s).

All three strings consist only of lowercase English letters.

It is possible that b and c coincide.

Output

Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.

Examples
input
aaa
a
b
output
aaa
input
pozdravstaklenidodiri
niste
dobri
output
nisteaadddiiklooprrvz
input
abbbaaccca
ab
aca
output
ababacabcc
Note

In the third sample, this optimal solutions has three non-overlaping substrings equal to either b or c on positions 1 – 2 (ab), 3 – 4 (ab), 5 – 7 (aca). In this sample, there exist many other optimal solutions, one of them would be acaababbcc.

给定A,B,C串,其中A串(可能)包含B或C串,现在可以任意变换A串的位置,使A串中包含B串,C串的总个数最大。

所以贪心下啊,统计字母个数

#include <bits/stdc++.h>
using namespace std;
char a[100100],b[100100],c[100100];
int A[30],B[30],C[30],S[30];
int main() {
    cin>>a>>b>>c;
    int len=strlen(a);
    for(int i=0; i<len; i++)
        A[a[i]-'a']++;
    len=strlen(b);
    for(int i=0; i<len; i++)
        B[b[i]-'a']++;
    len=strlen(c);
    for(int i=0; i<len; i++)
        C[c[i]-'a']++;
    int ans,x,y;
    ans=x=y=0;
    len=strlen(a)/strlen(b);
    for(int i=0; i<=len; i++) {
        int ok=1;
        memcpy(S,A,sizeof(A));
        for(int j=0; j<26; j++) {
            if(B[j]*i>S[j]) {
                ok=0;
                break;
            }
            S[j]-=B[j]*i;
        }
        if(!ok)
            continue;
        int t=1001000;
        for(int j=0; j<26; j++) {
            if(C[j]==0)
                continue;
            t=min(t,S[j]/C[j]);
        }
        if(t+i>ans) {
            ans=t+i;
            x=i;
            y=t;
        }
    }
    for(int i=0; i<x; i++)
        cout<<b;
    for(int i=0; i<y; i++)
        cout<<c;
    for(int i=0; i<26; i++) {
        for(int j=0; j<A[i]-x*B[i]-y*C[i]; j++)
            cout<<char('a'+i);
    }
    cout<<endl;
    return 0;
}